Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change checkout payments to a list in API

fowczareke6a2d092bbc9
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index fb9d93bf4c..89a6a3da3e 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -1,10 +1,12 @@
import graphene
+import graphene_django_optimizer as gql_optimizer
from ...checkout import models
from ...core.utils.taxes import get_taxes_for_address
from ..core.types.common import CountableDjangoObjectType
from ..core.types.money import TaxedMoney
from ..order.resolvers import resolve_shipping_methods
+from ..payment.types import Payment
from ..shipping.types import ShippingMethod
@@ -32,27 +34,31 @@ class CheckoutLine(CountableDjangoObjectType):
class Checkout(CountableDjangoObjectType):
- total_price = graphene.Field(
+ available_shipping_methods = graphene.List(
+ ShippingMethod, required=False,
+ description='Shipping methods that can be used with this order.')
+ is_shipping_required = graphene.Boolean(
+ description='Returns True, if checkout requires shipping.')
+ lines = graphene.List(
+ CheckoutLine, description=(
+ 'A list of checkout lines, each containing information about '
+ 'an item in the checkout.'))
+ payments = gql_optimizer.field(
+ graphene.List(
+ Payment, description='List of payments for the checkout'),
+ model_field='payments')
+ shipping_price = graphene.Field(
TaxedMoney,
- description=(
- 'The sum of the the checkout line prices, with all the taxes,'
- 'shipping costs, and discounts included.'))
+ description='The price of the shipping, with all the taxes included.')
subtotal_price = graphene.Field(
TaxedMoney,
description=(
'The price of the checkout before shipping, with taxes included.'))
- shipping_price = graphene.Field(
+ total_price = graphene.Field(
TaxedMoney,
- description='The price of the shipping, with all the taxes included.')
- lines = graphene.List(
- CheckoutLine, description=(
- 'A list of checkout lines, each containing information about '
- 'an item in the checkout.'))
- available_shipping_methods = graphene.List(
- ShippingMethod, required=False,
- description='Shipping methods that can be used with this order.')
- is_shipping_required = graphene.Boolean(
- description='Returns True, if checkout requires shipping.')
+ description=(
+ 'The sum of the the checkout line prices, with all the taxes,'
+ 'shipping costs, and discounts included.'))
class Meta:
description = 'Checkout object'
@@ -60,6 +66,9 @@ class Checkout(CountableDjangoObjectType):
interfaces = [graphene.relay.Node]
filter_fields = ['token']
+ def resolve_payments(self, info):
+ return self.payments.all()
+
def resolve_total_price(self, info):
taxes = get_taxes_for_address(self.shipping_address)
return self.get_total(taxes=taxes)
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index 1c29a02466..fe9f91e89f 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -554,6 +554,9 @@ def test_query_checkouts(
edges {
node {
token
+ payments{
+ id
+ }
}
}
}
@@ -565,6 +568,7 @@ def test_query_checkouts(
content = get_graphql_content(response)
received_checkout = content['data']['checkouts']['edges'][0]['node']
assert str(checkout.token) == received_checkout['token']
+ assert len(received_checkout['payments']) == checkout.payments.count()
def test_query_checkout_lines(