Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix gift cards automatic fulfillment (#10325)
Iga Karbowiak6a528259e3bd
diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex 036f3c4639..e16288f8c0 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -35,7 +35,6 @@ from ..discount.utils import (increase_voucher_usage,release_voucher_usage,)-from ..giftcard.utils import fulfill_non_shippable_gift_cardsfrom ..graphql.checkout.utils import (prepare_insufficient_stock_checkout_validation_error,)@@ -581,7 +580,11 @@ def _create_order(transaction.on_commit(lambda: order_created(- order_info=order_info, user=user, app=app, manager=manager+ order_info=order_info,+ user=user,+ app=app,+ manager=manager,+ site_settings=site_settings,))@@ -590,11 +593,6 @@ def _create_order(lambda: send_order_confirmation(order_info, checkout.redirect_url, manager))- if site_settings.automatically_fulfill_non_shippable_gift_card:- fulfill_non_shippable_gift_cards(- order, order_lines, site_settings, user, app, manager- )-return order@@ -977,7 +975,11 @@ def _post_create_order_actions(transaction.on_commit(lambda: order_created(- order_info=order_info, user=user, app=app, manager=manager+ order_info=order_info,+ user=user,+ app=app,+ manager=manager,+ site_settings=site_settings,))@@ -988,12 +990,6 @@ def _post_create_order_actions())- order_lines = [line.line for line in order_lines_info]- if site_settings.automatically_fulfill_non_shippable_gift_card:- fulfill_non_shippable_gift_cards(- order, order_lines, site_settings, user, app, manager- )-def _create_order_from_checkout(checkout_info: CheckoutInfo,diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.pyindex 594d93aac2..7d2fa4464c 100644--- a/saleor/checkout/tests/test_checkout_complete.py+++ b/saleor/checkout/tests/test_checkout_complete.py@@ -796,11 +796,15 @@ def test_create_order_with_many_gift_cards(def test_create_order_gift_card_bought(send_notification_mock,checkout_with_gift_card_items,+ payment_txn_captured,customer_user,shipping_method,is_anonymous_user,non_shippable_gift_card_product,):+ """Ensure that the gift cards will be fulfilled, when newly created order+ is captured."""+ # givencheckout_user = None if is_anonymous_user else customer_usercheckout = checkout_with_gift_card_itemscheckout.user = checkout_user@@ -815,6 +819,22 @@ def test_create_order_gift_card_bought(lines, _ = fetch_checkout_lines(checkout)checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ amount = calculations.calculate_checkout_total_with_gift_cards(+ manager, checkout_info, lines, customer_user.default_billing_address+ ).gross.amount++ payment_txn_captured.order = None+ payment_txn_captured.checkout = checkout+ payment_txn_captured.captured_amount = amount+ payment_txn_captured.total = amount+ payment_txn_captured.save(+ update_fields=["order", "checkout", "total", "captured_amount"]+ )++ txn = payment_txn_captured.transactions.first()+ txn.amount = amount+ txn.save(update_fields=["amount"])+subtotal = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,@@ -829,6 +849,7 @@ def test_create_order_gift_card_bought()total_gross = subtotal.gross + shipping_price.gross - checkout.discount+ # whenorder = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -844,6 +865,7 @@ def test_create_order_gift_card_bought(manager=manager,)+ # thenflush_post_commit_hooks()assert order.total.gross == total_grossflush_post_commit_hooks()@@ -855,6 +877,7 @@ def test_create_order_gift_card_bought().unit_price_gross)assert GiftCardEvent.objects.filter(gift_card=gift_card, type=GiftCardEvents.BOUGHT)+ flush_post_commit_hooks()send_notification_mock.assert_called_once_with(checkout_user,None,@@ -867,6 +890,70 @@ def test_create_order_gift_card_bought()[email protected]("saleor.giftcard.utils.send_gift_card_notification")[email protected]("is_anonymous_user", (True, False))+def test_create_order_gift_card_bought_order_not_captured_gift_cards_not_sent(+ send_notification_mock,+ checkout_with_gift_card_items,+ customer_user,+ shipping_method,+ is_anonymous_user,+):+ """Ensure that the gift cards will be not fulfilled, when newly created order+ is not captured."""+ # given+ checkout_user = None if is_anonymous_user else customer_user+ checkout = checkout_with_gift_card_items+ checkout.user = checkout_user+ checkout.billing_address = customer_user.default_billing_address+ checkout.shipping_address = customer_user.default_billing_address+ checkout.shipping_method = shipping_method+ checkout.tracking_code = "tracking_code"+ checkout.redirect_url = "https://www.example.com"+ checkout.save()++ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)++ subtotal = calculations.checkout_subtotal(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout.shipping_address,+ )+ shipping_price = calculations.checkout_shipping_price(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout.shipping_address,+ )+ total_gross = subtotal.gross + shipping_price.gross - checkout.discount++ # when+ order = _create_order(+ checkout_info=checkout_info,+ checkout_lines=lines,+ order_data=_prepare_order_data(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ discounts=None,+ taxes_included_in_prices=True,+ ),+ user=customer_user if not is_anonymous_user else AnonymousUser(),+ app=None,+ manager=manager,+ )++ # then+ flush_post_commit_hooks()+ flush_post_commit_hooks()+ assert order.total.gross == total_gross+ assert not GiftCard.objects.exists()+ send_notification_mock.assert_not_called()++@mock.patch("saleor.giftcard.utils.send_gift_card_notification")@pytest.mark.parametrize("is_anonymous_user", (True, False))def test_create_order_gift_card_bought_only_shippable_gift_card(diff --git a/saleor/checkout/tests/test_order_from_checkout.py b/saleor/checkout/tests/test_order_from_checkout.pyindex c526603cb0..ee7b46d583 100644--- a/saleor/checkout/tests/test_order_from_checkout.py+++ b/saleor/checkout/tests/test_order_from_checkout.py@@ -231,7 +231,9 @@ def test_create_order_gift_card_bought(is_anonymous_user,non_shippable_gift_card_product,app,+ payment_txn_captured,):+ # givencheckout_user = None if is_anonymous_user else customer_usercheckout = checkout_with_gift_card_itemscheckout.user = checkout_user@@ -260,6 +262,13 @@ def test_create_order_gift_card_bought()total_gross = subtotal.gross + shipping_price.gross - checkout.discount+ payment = payment_txn_captured+ payment.checkout = checkout+ payment.captured_amount = total_gross.amount+ payment.total = total_gross.amount+ payment.save(update_fields=["checkout", "captured_amount", "total"])++ # whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,@@ -270,6 +279,7 @@ def test_create_order_gift_card_bought(tracking_code="tracking_code",)+ # thenflush_post_commit_hooks()assert order.total.gross == total_grossflush_post_commit_hooks()@@ -281,6 +291,7 @@ def test_create_order_gift_card_bought().unit_price_gross)assert GiftCardEvent.objects.filter(gift_card=gift_card, type=GiftCardEvents.BOUGHT)+ flush_post_commit_hooks()send_notification_mock.assert_called_once_with(None,app,diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.pyindex c7a351017c..b4e1549ae8 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py@@ -426,10 +426,11 @@ def test_checkout_complete_gift_card_bought(customer_user,user_api_client,checkout_with_gift_card_items,- payment_dummy,address,shipping_method,+ payment_txn_captured,):+ # givencheckout = checkout_with_gift_card_itemscheckout.shipping_address = addresscheckout.shipping_method = shipping_method@@ -449,24 +450,28 @@ def test_checkout_complete_gift_card_bought(site_settings.automatically_fulfill_non_shippable_gift_card = Truesite_settings.save()- payment = payment_dummy+ payment = payment_txn_capturedpayment.is_active = Truepayment.order = None+ payment.captured_amount = total.gross.amountpayment.total = total.gross.amountpayment.currency = total.gross.currencypayment.checkout = checkoutpayment.save()- assert not payment.transactions.exists()orders_count = Order.objects.count()redirect_url = "https://www.example.com"variables = {"id": to_global_id_or_none(checkout), "redirectUrl": redirect_url}++ # whenresponse = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)+ # thencontent = get_graphql_content(response)data = content["data"]["checkoutComplete"]assert not data["errors"]+ flush_post_commit_hooks()assert Order.objects.count() == orders_count + 1order = Order.objects.first()assert order.status == OrderStatus.PARTIALLY_FULFILLEDdiff --git a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.pyindex 4e46663523..4465dfd1a2 100644--- a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py+++ b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py@@ -206,7 +206,9 @@ def test_order_from_checkout_gift_card_bought(checkout_with_gift_card_items,address,shipping_method,+ payment_txn_captured,):+ # givencheckout = checkout_with_gift_card_itemscheckout.shipping_address = addresscheckout.shipping_method = shipping_method@@ -216,29 +218,53 @@ def test_order_from_checkout_gift_card_bought(checkout.user = customer_usercheckout.save()+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)++ amount = calculations.calculate_checkout_total_with_gift_cards(+ manager, checkout_info, lines, address+ ).gross.amount++ payment_txn_captured.order = None+ payment_txn_captured.checkout = checkout+ payment_txn_captured.captured_amount = amount+ payment_txn_captured.total = amount+ payment_txn_captured.save(+ update_fields=["order", "checkout", "total", "captured_amount"]+ )++ txn = payment_txn_captured.transactions.first()+ txn.amount = amount+ txn.save(update_fields=["amount"])+site_settings.automatically_confirm_all_new_orders = Truesite_settings.automatically_fulfill_non_shippable_gift_card = Truesite_settings.save()orders_count = Order.objects.count()variables = {"id": graphene.Node.to_global_id("Checkout", checkout.pk)}++ # whenresponse = app_api_client.post_graphql(MUTATION_ORDER_CREATE_FROM_CHECKOUT,variables,permissions=[permission_handle_checkouts],)+ # thencontent = get_graphql_content(response)data = content["data"]["orderCreateFromCheckout"]assert not data["errors"]assert Order.objects.count() == orders_count + 1+ flush_post_commit_hooks()order = Order.objects.first()assert order.status == OrderStatus.PARTIALLY_FULFILLED- flush_post_commit_hooks()gift_card = GiftCard.objects.get()assert GiftCardEvent.objects.filter(gift_card=gift_card, type=GiftCardEvents.BOUGHT)+ flush_post_commit_hooks()send_notification_mock.assert_called_once_with(None,app,diff --git a/saleor/graphql/order/mutations/order_capture.py b/saleor/graphql/order/mutations/order_capture.pyindex 6aceeebe48..9a1c35ead0 100644--- a/saleor/graphql/order/mutations/order_capture.py+++ b/saleor/graphql/order/mutations/order_capture.py@@ -100,5 +100,6 @@ class OrderCapture(BaseMutation):amount,payment,info.context.plugins,+ info.context.site.settings,)return OrderCapture(order=order)diff --git a/saleor/graphql/order/mutations/order_confirm.py b/saleor/graphql/order/mutations/order_confirm.pyindex ea5ba405ad..f546c28cea 100644--- a/saleor/graphql/order/mutations/order_confirm.py+++ b/saleor/graphql/order/mutations/order_confirm.py@@ -92,6 +92,7 @@ class OrderConfirm(ModelMutation):payment.total,payment,manager,+ info.context.site.settings,))transaction.on_commit(diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex f09b54400b..18d3bcd404 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -3,7 +3,6 @@ from datetime import date, datetime, timedeltafrom decimal import Decimalfrom functools import reducefrom operator import getitem-from unittest import mockfrom unittest.mock import ANY, MagicMock, Mock, call, patchimport graphene@@ -33,6 +32,7 @@ from ....order import FulfillmentStatus, OrderEvents, OrderOrigin, OrderStatusfrom ....order import events as order_eventsfrom ....order.error_codes import OrderErrorCodefrom ....order.events import order_replacement_created+from ....order.fetch import fetch_order_infofrom ....order.interface import OrderTaxedPricesDatafrom ....order.models import Order, OrderEvent, OrderLine, get_order_numberfrom ....order.notifications import get_default_order_payload@@ -1539,24 +1539,38 @@ ORDER_CONFIRM_MUTATION = """"""+@patch("saleor.order.actions.handle_fully_paid_order")@patch("saleor.plugins.manager.PluginsManager.notify")@patch("saleor.payment.gateway.capture")def test_order_confirm(capture_mock,mocked_notify,+ handle_fully_paid_order_mock,staff_api_client,order_unconfirmed,permission_manage_orders,payment_txn_preauth,+ site_settings,):+ # givenpayment_txn_preauth.order = order_unconfirmed- payment_txn_preauth.save()+ payment_txn_preauth.captured_amount = order_unconfirmed.total.gross.amount+ payment_txn_preauth.total = order_unconfirmed.total.gross.amount+ payment_txn_preauth.save(update_fields=["order", "captured_amount", "total"])++ order_unconfirmed.total_charged = order_unconfirmed.total.gross+ order_unconfirmed.save(update_fields=["total_charged_amount"])+staff_api_client.user.user_permissions.add(permission_manage_orders)assert not OrderEvent.objects.exists()++ # whenresponse = staff_api_client.post_graphql(ORDER_CONFIRM_MUTATION,{"id": graphene.Node.to_global_id("Order", order_unconfirmed.id)},)++ # thenorder_data = get_graphql_content(response)["data"]["orderConfirm"]["order"]assert order_data["status"] == OrderStatus.UNFULFILLED.upper()@@ -1592,6 +1606,10 @@ def test_order_confirm(expected_payload,channel_slug=order_unconfirmed.channel.slug,)+ order_info = fetch_order_info(order_unconfirmed)+ handle_fully_paid_order_mock.assert_called_once_with(+ ANY, order_info, staff_api_client.user, None, site_settings+ )@patch("saleor.plugins.manager.PluginsManager.notify")@@ -4660,7 +4678,7 @@ def test_draft_order_complete_not_available_shipping_method(assert {error["field"] for error in data["errors"]} == {"shipping", "lines"}[email protected]("saleor.plugins.manager.PluginsManager.excluded_shipping_methods_for_order")+@patch("saleor.plugins.manager.PluginsManager.excluded_shipping_methods_for_order")def test_draft_order_complete_with_excluded_shipping_method(mocked_webhook,draft_order,@@ -4692,7 +4710,7 @@ def test_draft_order_complete_with_excluded_shipping_method(assert data["errors"][0]["field"] == "shipping"[email protected]("saleor.plugins.manager.PluginsManager.excluded_shipping_methods_for_order")+@patch("saleor.plugins.manager.PluginsManager.excluded_shipping_methods_for_order")def test_draft_order_complete_with_not_excluded_shipping_method(mocked_webhook,draft_order,@@ -6506,22 +6524,30 @@ ORDER_CAPTURE_MUTATION = """"""[email protected]("saleor.plugins.manager.PluginsManager.notify")+@patch("saleor.giftcard.utils.fulfill_non_shippable_gift_cards")+@patch("saleor.plugins.manager.PluginsManager.notify")def test_order_capture(mocked_notify,- channel_USD,+ fulfill_non_shippable_gift_cards_mock,staff_api_client,permission_manage_orders,payment_txn_preauth,staff_user,+ site_settings,):+ # givenorder = payment_txn_preauth.order+order_id = graphene.Node.to_global_id("Order", order.id)amount = float(payment_txn_preauth.total)variables = {"id": order_id, "amount": amount}++ # whenresponse = staff_api_client.post_graphql(ORDER_CAPTURE_MUTATION, variables, permissions=[permission_manage_orders])++ # thencontent = get_graphql_content(response)data = content["data"]["orderCapture"]["order"]order.refresh_from_db()@@ -6565,6 +6591,9 @@ def test_order_capture(expected_payment_payload,channel_slug=order.channel.slug,)+ fulfill_non_shippable_gift_cards_mock.assert_called_once_with(+ order, list(order.lines.all()), site_settings, staff_api_client.user, None, ANY+ )@patch("saleor.plugins.manager.PluginsManager.is_event_active_for_any_plugin")diff --git a/saleor/order/actions.py b/saleor/order/actions.pyindex 6fc506e6a2..91303babb1 100644--- a/saleor/order/actions.py+++ b/saleor/order/actions.py@@ -84,6 +84,7 @@ def order_created(app: Optional["App"],manager: "PluginsManager",from_draft: bool = False,+ site_settings: Optional["SiteSettings"] = None,):order = order_info.orderevents.order_created_event(order=order, user=user, app=app, from_draft=from_draft)@@ -98,6 +99,7 @@ def order_created(amount=payment.total,payment=payment,manager=manager,+ site_settings=site_settings,)elif order.is_pre_authorized():order_authorized(@@ -135,7 +137,10 @@ def handle_fully_paid_order(order_info: "OrderInfo",user: Optional["User"] = None,app: Optional["App"] = None,+ site_settings: Optional["SiteSettings"] = None,):+ from ..giftcard.utils import fulfill_non_shippable_gift_cards+order = order_info.orderevents.order_fully_paid_event(order=order, user=user, app=app)if order_info.customer_email:@@ -147,6 +152,16 @@ def handle_fully_paid_order(except Exception:# Analytics failing should not abort the checkout flowlogger.exception("Recording order in analytics failed")++ if site_settings is None:+ site_settings = Site.objects.get_current().settings++ if site_settings.automatically_fulfill_non_shippable_gift_card:+ order_lines = [line.line for line in order_info.lines_data]+ fulfill_non_shippable_gift_cards(+ order, order_lines, site_settings, user, app, manager+ )+manager.order_fully_paid(order)manager.order_updated(order)@@ -300,6 +315,7 @@ def order_captured(amount: "Decimal",payment: "Payment",manager: "PluginsManager",+ site_settings: Optional["SiteSettings"] = None,):order = order_info.orderevents.payment_captured_event(@@ -307,7 +323,7 @@ def order_captured()manager.order_updated(order)if order.is_fully_paid():- handle_fully_paid_order(manager, order_info, user, app)+ handle_fully_paid_order(manager, order_info, user, app, site_settings)def fulfillment_tracking_updated(diff --git a/saleor/order/tests/test_order_actions.py b/saleor/order/tests/test_order_actions.pyindex 713035c3c6..cf287f6b96 100644--- a/saleor/order/tests/test_order_actions.py+++ b/saleor/order/tests/test_order_actions.py@@ -4,6 +4,8 @@ from unittest.mock import patchimport pytestfrom prices import Money, TaxedMoney+from ...giftcard import GiftCardEvents+from ...giftcard.models import GiftCard, GiftCardEventfrom ...order.fetch import OrderLineInfo, fetch_order_infofrom ...payment import ChargeStatus, PaymentError, TransactionKindfrom ...payment.models import Payment@@ -23,7 +25,7 @@ from ..actions import (mark_order_as_paid,order_refunded,)-from ..models import Fulfillment+from ..models import Fulfillment, OrderLinefrom ..notifications import (send_fulfillment_confirmation_to_customer,send_payment_confirmation,@@ -135,6 +137,136 @@ def test_handle_fully_paid_order_no_email(mock_send_payment_confirmation, order)assert not mock_send_payment_confirmation.called+@patch("saleor.giftcard.utils.send_gift_card_notification")+@patch("saleor.order.actions.send_payment_confirmation")+def test_handle_fully_paid_order_gift_cards_created(+ mock_send_payment_confirmation,+ send_notification_mock,+ site_settings,+ order_with_lines,+ non_shippable_gift_card_product,+ shippable_gift_card_product,+):+ """Ensure the non shippable gift card are fulfilled when the flag for automatic+ fulfillment non shippable gift card is set."""+ # given+ site_settings.automatically_fulfill_non_shippable_gift_card = True+ site_settings.save(update_fields=["automatically_fulfill_non_shippable_gift_card"])++ order = order_with_lines++ non_shippable_gift_card_line = order_with_lines.lines.first()+ non_shippable_variant = non_shippable_gift_card_product.variants.get()+ non_shippable_gift_card_line.variant = non_shippable_variant+ non_shippable_gift_card_line.is_gift_card = True+ non_shippable_gift_card_line.is_shipping_required = False+ non_shippable_gift_card_line.quantity = 1+ allocation = non_shippable_gift_card_line.allocations.first()+ allocation.quantity_allocated = 1+ allocation.save(update_fields=["quantity_allocated"])++ shippable_gift_card_line = order_with_lines.lines.last()+ shippable_variant = shippable_gift_card_product.variants.get()+ shippable_gift_card_line.variant = shippable_variant+ shippable_gift_card_line.is_gift_card = True+ shippable_gift_card_line.is_shipping_required = True+ shippable_gift_card_line.quantity = 1++ OrderLine.objects.bulk_update(+ [non_shippable_gift_card_line, shippable_gift_card_line],+ ["variant", "is_gift_card", "is_shipping_required", "quantity"],+ )++ manager = get_plugins_manager()++ order.payments.add(Payment.objects.create())+ order_info = fetch_order_info(order)++ # when+ handle_fully_paid_order(manager, order_info)++ # then+ flush_post_commit_hooks()+ assert order.events.filter(type=OrderEvents.ORDER_FULLY_PAID)++ mock_send_payment_confirmation.assert_called_once_with(order_info, manager)++ flush_post_commit_hooks()+ gift_card = GiftCard.objects.get()+ assert gift_card.initial_balance == non_shippable_gift_card_line.unit_price_gross+ assert GiftCardEvent.objects.filter(gift_card=gift_card, type=GiftCardEvents.BOUGHT)++ send_notification_mock.assert_called_once_with(+ None,+ None,+ order.user,+ order.user_email,+ gift_card,+ manager,+ order.channel.slug,+ resending=False,+ )+++@patch("saleor.giftcard.utils.send_gift_card_notification")+@patch("saleor.order.actions.send_payment_confirmation")+def test_handle_fully_paid_order_gift_cards_not_created(+ mock_send_payment_confirmation,+ send_notification_mock,+ site_settings,+ order_with_lines,+ non_shippable_gift_card_product,+ shippable_gift_card_product,+):+ """Ensure the non shippable gift card are not fulfilled when the flag for+ automatic fulfillment non shippable gift card is not set."""+ # given+ site_settings.automatically_fulfill_non_shippable_gift_card = False+ site_settings.save(update_fields=["automatically_fulfill_non_shippable_gift_card"])++ order = order_with_lines++ non_shippable_gift_card_line = order_with_lines.lines.first()+ non_shippable_variant = non_shippable_gift_card_product.variants.get()+ non_shippable_gift_card_line.variant = non_shippable_variant+ non_shippable_gift_card_line.is_gift_card = True+ non_shippable_gift_card_line.is_shipping_required = False+ non_shippable_gift_card_line.quantity = 1+ allocation = non_shippable_gift_card_line.allocations.first()+ allocation.quantity_allocated = 1+ allocation.save(update_fields=["quantity_allocated"])++ shippable_gift_card_line = order_with_lines.lines.last()+ shippable_variant = shippable_gift_card_product.variants.get()+ shippable_gift_card_line.variant = shippable_variant+ shippable_gift_card_line.is_gift_card = True+ shippable_gift_card_line.is_shipping_required = True+ shippable_gift_card_line.quantity = 1++ OrderLine.objects.bulk_update(+ [non_shippable_gift_card_line, shippable_gift_card_line],+ ["variant", "is_gift_card", "is_shipping_required", "quantity"],+ )++ manager = get_plugins_manager()++ order.payments.add(Payment.objects.create())+ order_info = fetch_order_info(order)++ # when+ handle_fully_paid_order(manager, order_info)++ # then+ flush_post_commit_hooks()+ assert order.events.filter(type=OrderEvents.ORDER_FULLY_PAID)++ mock_send_payment_confirmation.assert_called_once_with(order_info, manager)++ flush_post_commit_hooks()+ assert not GiftCard.objects.exists()+ send_notification_mock.assert_not_called++def test_mark_as_paid(admin_user, draft_order):manager = get_plugins_manager()mark_order_as_paid(draft_order, admin_user, None, manager)