# `Shopifex.RedirectAfterAgent`
[🔗](https://github.com/ericdude4/shopifex/blob/main/lib/shopifex/redirect_after_agent.ex#L1)

Caches the post-payment charge binding keyed by Shopify charge id, so
`complete_payment/2` can recover and verify it when Shopify redirects the merchant back.

Values stored here are opaque signed charge-binding strings produced by
`ShopifexWeb.PaymentController.bind_charge/4`.

## Multi-node deploys: use `Shopifex.RedirectAfter.Ecto`

This default implementation is an in-memory `Agent` local to **one node**. A
charge confirmation can redirect to `/payment/complete` on a *different* node
than the one that handled `select_plan` (e.g. behind a load balancer / on a
multi-node deploy like Fly.io), in which case the lookup misses and the grant
is not created. It is intermittent and won't show up in single-node dev.

If you run more than one node, configure the shipped, multi-node-safe
`Shopifex.RedirectAfter.Ecto` (a DB-backed table) instead:

    config :shopifex, :redirect_after_agent, Shopifex.RedirectAfter.Ecto

`mix shopifex.install` generates that config and the backing migration for new
apps. Any module implementing this behaviour works — the config seam is just
`Application.get_env(:shopifex, :redirect_after_agent, __MODULE__)`.

When a lookup misses, `complete_payment/2` logs an actionable `Logger.error`
(the usual cause is this node-local cache on a multi-node deploy), so dropped
grants are observable rather than invisible.

`set/2` and `get/1` agree on key type: both coerce binary ids with `Integer.parse/1`
and treat non-integers as a miss (`nil` / no-op `:ok`) without raising.

# `get`

```elixir
@callback get(charge_id :: String.t() | pos_integer()) :: String.t() | nil
```

Retrieve the redirect url from cache with key charge_id and
remove the key from cache.

# `set`

```elixir
@callback set(charge_id :: String.t() | pos_integer(), redirect_uri :: String.t()) :: :ok
```

Set a redirect url in cache with key charge_id.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get`

# `set`

# `start_link`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
