Skip to content
Katabench
Try free

The Leaky Payment Port

Hard About 40 min Free, no account needed

A checkout service is welded to a Stripe client and passes vendor DTOs around. Someone half-extracted an IPaymentGateway port, but it leaks Stripe types through its own signature. Make the port vendor-neutral with a real anti-corruption layer, not an interface that smuggles the SDK through.

The brief

You've inherited the checkout flow. Checkout.CheckoutService.Pay(amountCents) takes a payment by constructing a concrete Vendor.StripeClient, building a Vendor.StripeChargeRequest, and reading a Vendor.StripeChargeResult straight off the call. The domain service is welded to the Stripe SDK: swap processors, or take a breaking SDK upgrade, and the change tears right through the heart of checkout.

Someone already saw the smell and started the obvious fix. There's an IPaymentGateway interface sitting next to the service. But look closely: its method is StripeChargeResult Charge( StripeChargeRequest req). The "abstraction" is typed entirely in the vendor's own DTOs. So CheckoutService never even adopted it; depending on that port would buy nothing, because the vendor would still ride straight through its signature.

The trap

The tempting move is to finish that half-built extraction: point CheckoutService at the existing IPaymentGateway, stop new-ing StripeClient yourself, and seal up the adapter. Do exactly that and most of the rules go green. But one stays stubbornly red, and it's the one that matters. An interface whose signature speaks Stripe* types is not an abstraction over the vendor. It is the vendor SDK wearing a trench coat: the coupling didn't leave, it just moved into the contract.

Your job

Make the port a real seam. Figure out what CheckoutService actually needs to say to take a payment, in your vocabulary rather than Stripe's, and express the port in those terms. Then give the Stripe knowledge exactly one home. The behavior must stay byte-for-byte identical: same "charged:..." string for the same amountCents.

How it's graded

Your submission must (1) still pass the behavior tests (identical charged: strings) and (2) satisfy every rule shown in the results, including the one pinning that CheckoutService references no Stripe* type at all, not even through the port's signature. The naive finish-the-extraction clears the easy rules and leaves that one failing; only a port typed in neutral terms, with an adapter translating to and from the vendor, turns them all green.

"We extracted an interface" is only half the story. An abstraction that leaks the type it was meant to hide hasn't decoupled anything. It has just relocated the dependency into the contract.

How it is graded

Executable structural checks grade the shape of your types as well as their behavior.

SOLID principles exercises →

What it practices

Anti-corruption layer
Translate a legacy or external model at the boundary, and replace it incrementally behind that port.
Dependency inversion
Point dependencies at abstractions the core owns, never at outer mechanisms.

Do these first

Related katas