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

A link to the provider's own billing page for one customer (Stripe's customer portal), made with
`MishkaPay.portal_session/1`. Send the buyer to `:url`; there they update their card, see their
invoices, and change or cancel their plan as the provider's settings allow, then come back to
`:return_url`. What they change reaches the host through its webhooks. A guarded_struct.

What the caller gives: `:provider`, `:tenant`, `:customer_id`, `:return_url` (`https`, or `http`
on `localhost`), and optionally `:configuration`, the provider's id of a portal setup other than
its default.

`:flow` opens the page on one task instead of its home, and sends the buyer back to
`:return_url` when it is done: `:subscription_cancel` or `:subscription_update` (with
`:subscription_id`), or `:payment_method_update` (the card on file).

What the provider fills in: `:id` and `:url`. The link is short-lived: make one per click.

# `t`

```elixir
@type t() :: %MishkaPay.PortalSession{
  configuration: String.t() | nil,
  customer_id: String.t(),
  flow:
    (:subscription_cancel | :subscription_update | :payment_method_update) | nil,
  id: String.t() | nil,
  provider: String.t(),
  return_url: String.t(),
  subscription_id: String.t() | nil,
  tenant: term() | nil,
  url: String.t() | 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 |  |  |  |
| `:customer_id` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty)` |
| `:return_url` | `String.t()` | yes |  |  | `sanitize(trim) validate(not_nil_value, string, not_empty)`<br>validator `{MishkaPay.Checkout, :return_url}` |
| `:configuration` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:flow` | `:subscription_cancel` \| `:subscription_update` \| `:payment_method_update` \| `nil` | no |  |  | `validate(enum=Atom[subscription_cancel::subscription_update::payment_method_update])`<br>validator `{MishkaPay.PortalSession, :flow}` |
| `:subscription_id` | `String.t()` \| `nil` | no |  |  | `sanitize(trim) validate(string, not_empty)` |
| `:id` | `String.t()` \| `nil` | no |  |  | `validate(string)` |
| `:url` | `String.t()` \| `nil` | no |  |  | `validate(string)` |

# `builder`

# `enforce_keys`

# `enforce_keys`

# `example`

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

# `keys`

# `keys`

---

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