# `MishkaPay.ProviderKit`
[🔗](https://github.com/mishka-group/mishka_pay/blob/v0.0.1/lib/mishka_pay/provider_kit.ex#L5)

What every provider adapter needs the same way, so each one keeps the same rules: idempotency
keys from a caller's own ids, the site's refund rule (`MishkaPay.Credentials`, `:refunds`), and
an `:invalid` error on a field. Stripe and PayPal use it; a provider a project writes can too.

# `idempotency_key`

```elixir
@spec idempotency_key(String.t(), term(), term()) :: String.t() | nil
```

The idempotency key of `operation` for `material` (a reference, or anything that names one
request) and `tenant`: the same inputs always give the same key, so a request sent again is the
same request at the provider. `nil` material gives `nil`: no key.

# `invalid`

```elixir
@spec invalid(atom(), String.t()) :: {:error, Splode.Error.t()}
```

An `:invalid` class error on `field` with `message`, as a builder error would be.

# `refund_key`

```elixir
@spec refund_key(MishkaPay.Refund.t(), map()) ::
  {:ok, String.t()} | {:error, Splode.Error.t()}
```

The idempotency key of a refund under the site's rule: a site that refunds once has one refund
per payment, so the payment names it; one that refunds many times names each refund by its
`:reference`, which it then needs.

# `refundable`

```elixir
@spec refundable(MishkaPay.Refund.t(), MishkaPay.Payment.t(), map()) ::
  :ok | {:error, Splode.Error.t()}
```

Whether `refund` may go to the provider for `payment` as it is now: refused when the site
refunds once and the payment has a refund, when nothing is left, or when a part refund is in
another currency or over what is left. What is left counts from what the provider took, a part
when a held payment was captured in part.

---

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