#19470·saleor

Circular dependency between saleor/payment and saleor/giftcard introduced by the gift-card payment gateway (#18579)

Author: damienmeurCreated Jul 14, 2026Updated Jul 27, 2026

What are you trying to achieve?

Keep the dependency between saleor/payment and saleor/giftcard one-way. #18579 ("Gift cards as payment method") made it two-way: the new saleor/giftcard/gateway.py imports payment, payment.interface, payment.models, and payment.utils at the top level (lines 18-26), while payment/gateway.py:14 and payment/utils.py:35 import giftcard.const in the other direction. The back-edge only runs because payment/utils.py defers from ..giftcard.gateway import transaction_initialize_session_with_gift_card_payment_method into the body of handle_transaction_initialize_session (line 1927) — hoisting it to the top level is an ImportError.

Steps to reproduce the problem

On current main (b8f2389a):

bash
git grep -n "from \.\.payment" saleor/giftcard/gateway.py
git grep -n "giftcard" saleor/payment/gateway.py saleor/payment/utils.py

What did you expect to happen?

No import cycle between the two apps. The friction was already felt at authoring time — the #18579 commit message includes "Move some functions around to fix circular import issues", "Move import", and "Eradicate local imports" — but the cycle itself shipped and the deferred import is still the load-bearing workaround. Two ways to make the dependency one-way again and delete it: move the built-in gift-card gateway under saleor/payment/gateways/ next to the existing ones (stripe, braintree, ...), or relocate the GIFT_CARD_PAYMENT_GATEWAY_* constants into payment. Happy to send a PR for whichever direction you prefer.

Environment

Saleor version: main @ b8f2389a OS and version: any (import structure, not OS-specific)