MishkaPay.Product (Mishka Pay v0.0.1)

Copy Markdown View Source

Something sold, as the provider keeps it in its catalog (prod_... at Stripe), with its prices (MishkaPay.Price with :product_id). A guarded_struct.

Made with MishkaPay.create_product/1, changed with MishkaPay.update_product/1, taken off sale with MishkaPay.archive_product/3, read with MishkaPay.fetch_product/3 and MishkaPay.list_products/3. A checkout sells a catalog price by its id (items: [%{id: "price_..."}]).

What the caller gives:

  • :provider, :tenant: which provider, with whose keys.
  • :id: optional, the product's own id ("shop-ebook"); the provider makes one when it is left out.
  • :name, :description: what the buyer sees.
  • :tax_code: the provider's tax category, such as Stripe's "txcd_10302000".
  • :active: on sale (true by default); false keeps it for past sales only.
  • :metadata: extra pairs, string keys to string values.

What the provider fills in: :default_price_id, :created_at.

Summary

Types

t()

The struct that builder/1 returns.

Functions

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

Types

t()

@type t() :: %MishkaPay.Product{
  active: boolean() | nil,
  created_at: DateTime.t() | nil,
  default_price_id: String.t() | nil,
  description: String.t() | nil,
  id: String.t() | nil,
  metadata: map() | nil,
  name: String.t() | nil,
  provider: String.t() | nil,
  tax_code: String.t() | nil,
  tenant: term() | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t() | nilnosanitize(trim) validate(string, not_empty)
:tenantterm() | nilno
:idString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=200)
:nameString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=250)
:descriptionString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=1000)
:tax_codeString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=100)
:activeboolean() | nilnovalidate(boolean)
:metadatamap() | nilno%{}validate(map)<br>validator {MishkaPay.Checkout, :metadata}
:default_price_idString.t() | nilnovalidate(string)
:created_atDateTime.t() | nilnovalidate(struct)

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)