Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix review remarks
Marcin Gębala8d08ed69b684
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex 8031853abb..b9bd58ad2e 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -453,7 +453,7 @@ class CheckoutComplete(BaseMutation):class Meta:description = ('Completes the checkout. As a result a new order is created and '- 'a payment charge is made. This action requires a succesfull '+ 'a payment charge is made. This action requires a successful ''payment before it can be performed.')@classmethoddiff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex cb89d28dd7..38856bfea7 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -200,8 +200,8 @@ class Order(CountableDjangoObjectType):interfaces = [relay.Node]model = models.Orderexclude_fields = [- 'shipping_price_gross', 'shipping_price_net', 'total_gross',- 'total_net']+ 'checkout_token', 'shipping_price_gross', 'shipping_price_net',+ 'total_gross', 'total_net']@staticmethoddef resolve_shipping_price(self, info):diff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex 94b406c684..0231583bde 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -144,37 +144,6 @@ class PaymentCapture(BaseMutation):return PaymentCapture(payment=payment, errors=errors)-class PaymentCharge(BaseMutation):- payment = graphene.Field(Payment, description='Updated payment')-- class Arguments:- payment_id = graphene.ID(required=True, description='Payment ID')- payment_token = graphene.String(- required=True,- description='One-time-use reference to payment information')- amount = Decimal(description='Transaction amount')-- class Meta:- description = 'Authorize the payment'-- @classmethod- @permission_required('order.manage_orders')- def mutate(cls, root, info, payment_id, payment_token, amount=None):- errors = []- payment = cls.get_node_or_error(- info, payment_id, errors, 'payment_id', only_type=Payment)-- if not payment:- return PaymentCharge(errors=errors)-- try:- gateway_charge(payment, payment_token, amount)- except PaymentError as exc:- msg = str(exc)- cls.add_error(field=None, message=msg, errors=errors)- return PaymentCharge(payment=payment, errors=errors)--class PaymentRefund(PaymentCapture):@classmethod@permission_required('order.manage_orders')diff --git a/saleor/graphql/payment/schema.py b/saleor/graphql/payment/schema.pyindex 739eded58f..2447e14ade 100644--- a/saleor/graphql/payment/schema.py+++ b/saleor/graphql/payment/schema.py@@ -4,8 +4,7 @@ from graphql_jwt.decorators import permission_requiredfrom ..core.fields import PrefetchingConnectionFieldfrom .enums import PaymentGatewayEnumfrom .mutations import (- PaymentAuthorize, PaymentCapture, PaymentCharge, PaymentRefund,- PaymentVoid)+ PaymentAuthorize, PaymentCapture, PaymentRefund, PaymentVoid)from .resolvers import resolve_payment_client_token, resolve_paymentsfrom .types import Payment@@ -31,6 +30,5 @@ class PaymentQueries(graphene.ObjectType):class PaymentMutations(graphene.ObjectType):payment_authorize = PaymentAuthorize.Field()payment_capture = PaymentCapture.Field()- payment_charge = PaymentCharge.Field()payment_refund = PaymentRefund.Field()payment_void = PaymentVoid.Field()diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 4b2c8f3306..277cbbafa3 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -878,7 +878,6 @@ type Mutations {variantImageUnassign(imageId: ID!, variantId: ID!): VariantImageUnassignpaymentAuthorize(paymentId: ID!, paymentToken: String!): PaymentAuthorizepaymentCapture(amount: Decimal, paymentId: ID!): PaymentCapture- paymentCharge(amount: Decimal, paymentId: ID!, paymentToken: String!): PaymentChargepaymentRefund(amount: Decimal, paymentId: ID!): PaymentRefundpaymentVoid(paymentId: ID!): PaymentVoidpageCreate(input: PageInput!): PageCreate@@ -1238,19 +1237,19 @@ type Payment implements Node {created: DateTime!modified: DateTime!chargeStatus: PaymentChargeStatusEnum!+ billingEmail: String!+ customerIpAddress: String+ extraData: String!token: String!total: MoneycapturedAmount: Moneycheckout: Checkoutorder: Order- billingEmail: String!ccFirstDigits: String!ccLastDigits: String!ccBrand: String!ccExpMonth: IntccExpYear: Int- customerIpAddress: String- extraData: String!transactions: [Transaction]actions: [OrderAction]!billingAddress: Address@@ -1269,11 +1268,6 @@ type PaymentCapture {payment: Payment}-type PaymentCharge {- errors: [Error!]- payment: Payment-}-enum PaymentChargeStatusEnum {CHARGEDNOT_CHARGEDdiff --git a/tests/api/test_payment.py b/tests/api/test_payment.pyindex 943fc13767..f9457c5e3d 100644--- a/tests/api/test_payment.py+++ b/tests/api/test_payment.py@@ -248,77 +248,6 @@ def test_payment_capture_gateway_error(assert not txn.is_success-CHARGE_QUERY = """- mutation PaymentCharge($paymentId: ID!, $paymentToken: String!, $amount: Decimal!) {- paymentCharge(paymentId: $paymentId, paymentToken: $paymentToken, amount: $amount) {- payment {- id,- chargeStatus- }- errors {- field- message- }- }- }-"""---def test_payment_charge_success(- staff_api_client, permission_manage_orders, payment_dummy):- payment = payment_dummy- assert payment.charge_status == ChargeStatus.NOT_CHARGED-- payment_id = graphene.Node.to_global_id(- 'Payment', payment.pk)- variables = {- 'paymentId': payment_id,- 'paymentToken': 'Fake',- 'amount': str(payment.total)}- response = staff_api_client.post_graphql(- CHARGE_QUERY, variables, permissions=[permission_manage_orders])- content = get_graphql_content(response)- data = content['data']['paymentCharge']- assert not data['errors']- payment.refresh_from_db()- assert payment.charge_status == ChargeStatus.CHARGED- assert payment.transactions.count() == 2- capture_txn, auth_txn = payment.transactions.all()- assert auth_txn.kind == TransactionKind.AUTH- assert capture_txn.kind == TransactionKind.CAPTURE---def test_payment_charge_gateway_error(- staff_api_client, permission_manage_orders, payment_dummy,- monkeypatch):- payment = payment_dummy- assert payment.charge_status == ChargeStatus.NOT_CHARGED-- payment_id = graphene.Node.to_global_id(- 'Payment', payment.pk)- variables = {- 'paymentId': payment_id,- 'paymentToken': 'Fake',- 'amount': str(payment.total)}- monkeypatch.setattr(- 'saleor.payment.gateways.dummy.dummy_success', lambda: False)- response = staff_api_client.post_graphql(- CHARGE_QUERY, variables, permissions=[permission_manage_orders])- content = get_graphql_content(response)- data = content['data']['paymentCharge']- assert data['errors']- assert data['errors'][0]['field'] is None- assert data['errors'][0]['message']-- payment.refresh_from_db()- assert payment.charge_status == ChargeStatus.NOT_CHARGED- assert payment.transactions.count() == 1- txn = payment.transactions.last()- assert txn.kind == TransactionKind.AUTH- assert not txn.is_success--REFUND_QUERY = """mutation PaymentRefund($paymentId: ID!, $amount: Decimal!) {paymentRefund(paymentId: $paymentId, amount: $amount) {diff --git a/tests/test_payment.py b/tests/test_payment.pyindex be9f6a206e..fa8be06045 100644--- a/tests/test_payment.py+++ b/tests/test_payment.py@@ -154,9 +154,8 @@ def test_mark_as_paid(admin_user, draft_order):payment = draft_order.payments.last()assert payment.charge_status == ChargeStatus.CHARGEDassert payment.captured_amount == draft_order.total.gross.amount- assert (- draft_order.events.last().type == OrderEvents.ORDER_MARKED_AS_PAID.- value)+ assert draft_order.events.last().type == (+ OrderEvents.ORDER_MARKED_AS_PAID.value)def test_clean_mark_order_as_paid(payment_txn_preauth):