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

A payment method saved for later on the site's own page, with the provider's card form (Stripe
Elements) and no charge: made on the server with `MishkaPay.create_setup_intent/1`, its
`:client_secret` handed to that buyer's browser, where the provider's script shows the form and
confirms it. Read with `MishkaPay.fetch_setup_intent/3`, confirmed on the server with
`MishkaPay.confirm_setup_intent/4`, and ended with `MishkaPay.cancel_setup_intent/3`. Once it
succeeded, its `:payment_method_id` is on the customer: `MishkaPay.list_payment_methods/3`
lists it. A guarded_struct.

What the caller gives:

  * `:provider`, `:tenant`: which provider, with whose keys.
  * `:customer_id`: the provider customer who keeps the payment method. Without one, the
    payment method is saved but on no customer, and can be used once.
  * `:payment_method_id`: a payment method to save, to confirm it without the form.
  * `:usage`: `:off_session` (the provider's default) for later charges without the buyer,
    `:on_session` for later payments the buyer makes.
  * `:automatic_payment_methods`: `true` (the default) offers the payment methods turned on in
    the provider's dashboard; `false` offers cards only.
  * `:description`, `:metadata`: kept with it.
  * `:reference`: the caller's own id for it; it makes the idempotency key, so the same
    reference never makes two, and it comes back on it.

What the provider fills in: `:id` (`seti_...` at Stripe), `:client_secret` (send it only to
that buyer's page), `:status` (`:requires_payment_method`, `:requires_confirmation`,
`:requires_action`, `:processing`, `:succeeded` or `:canceled`), `:failure_code`,
`:failure_message` and `:created_at`.

# `t`

```elixir
@type t() :: %MishkaPay.SetupIntent{
  automatic_payment_methods: boolean() | nil,
  client_secret: String.t() | nil,
  created_at: DateTime.t() | nil,
  customer_id: String.t() | nil,
  description: String.t() | nil,
  failure_code: String.t() | nil,
  failure_message: String.t() | nil,
  id: String.t() | nil,
  metadata: map() | nil,
  payment_method_id: String.t() | nil,
  provider: String.t(),
  reference: String.t() | nil,
  status: atom() | nil,
  tenant: term() | nil,
  usage: (:on_session | :off_session) | nil
}
```

The struct that `builder/1` returns.

| Field | Type | Required | Default | Description | Derives |
| --- | --- | --- | --- | --- | --- |
| `:provider` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty)` |
| `:tenant` | `term()` \| `nil` | no |  |  |  |
| `:id` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:customer_id` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:payment_method_id` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:usage` | `:on_session` \| `:off_session` \| `nil` | no |  |  | `validate(enum=Atom[on_session::off_session])`<br>validator `{MishkaPay.PaymentIntent, :usage}` |
| `:automatic_payment_methods` | `boolean()` \| `nil` | no |  |  | `validate(boolean)` |
| `:description` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, max_len=1000)` |
| `:reference` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty, max_len=200)` |
| `:metadata` | `map()` \| `nil` | no | `%{}` |  | `validate(map)`<br>validator `{MishkaPay.Checkout, :metadata}` |
| `:client_secret` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:status` | `atom()` \| `nil` | no |  |  | `validate(enum=Atom[requires_payment_method::requires_confirmation::requires_action::processing::succeeded::canceled])` |
| `:failure_code` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:failure_message` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:created_at` | `DateTime.t()` \| `nil` | no |  |  | `validate(struct)` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

A sample %MishkaPay.SetupIntent{} populated from defaults + type-based fallbacks.

# `keys`

# `keys`

# `statuses`

```elixir
@spec statuses() :: [atom()]
```

The statuses a setup intent can have.

---

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