MishkaPay.Invoice.Draft (Mishka Pay v0.0.1)

Copy Markdown View Source

A bill to make for a customer, outside any subscription, with MishkaPay.create_invoice/1: a service sold by hand, an order paid later. The provider makes it as a draft and answers it as a MishkaPay.Invoice; MishkaPay.finalize_invoice/3 opens it for payment, MishkaPay.send_invoice/3 emails it, and MishkaPay.pay_invoice/4, void_invoice/3, mark_invoice_uncollectible/3 and delete_invoice/3 end it. A guarded_struct.

  • :provider, :tenant: as for a checkout.
  • :customer_id: the provider customer it bills (MishkaPay.create_customer/1).
  • :items: one or more MishkaPay.Price, all in one currency: a catalog price by its :id, or a :name with an :amount and a :quantity. A recurring price is refused: a plan starts with a checkout. An item's :tax_rate_ids add the seller's own tax rates to it.
  • :tax_rate_ids: the seller's own tax rates (MishkaPay.TaxRate) for every line of the bill that names none of its own.
  • :collection: :charge_automatically (the default) charges the customer's saved payment method when it is finalized; :send_invoice emails a bill they pay on the provider's page, within :days_until_due (30 unless given).
  • :description, :footer: text on the bill.
  • :reference: the caller's own id for the bill, such as an order id; it makes the idempotency key, so the same reference never makes two bills, and it comes back on it.
  • :metadata: extra pairs kept with it.

Stripe sells as merchant of record (Managed Payments) only through checkouts and payment links: a site with merchant of record on cannot send one-off bills.

Summary

Types

t()

The struct that builder/1 returns.

Functions

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

Types

t()

@type t() :: %MishkaPay.Invoice.Draft{
  collection: (:charge_automatically | :send_invoice) | nil,
  customer_id: String.t(),
  days_until_due: pos_integer() | nil,
  description: String.t() | nil,
  footer: String.t() | nil,
  items: [MishkaPay.Price.t()],
  metadata: map() | nil,
  provider: String.t(),
  reference: String.t() | nil,
  tax_rate_ids: list() | nil,
  tenant: term() | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:tenantterm() | nilno
:customer_idString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:items[MishkaPay.Price.t()]yesvalidate(not_nil_value, list)
:collection:charge_automatically | :send_invoice | nilno:charge_automaticallyvalidate(not_nil_value, enum=Atom[charge_automatically::send_invoice])<br>validator {MishkaPay.Invoice, :collection}
:days_until_duepos_integer() | nilnovalidate(integer, min_len=1)
:tax_rate_idslist() | nilnosanitize(each=[trim]) validate(list, each=[string, not_empty])
:descriptionString.t() | nilnosanitize(trim) validate(string, max_len=1500)
:footerString.t() | nilnosanitize(trim) validate(string, max_len=5000)
:referenceString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=200)
:metadatamap() | nilno%{}validate(map)<br>validator {MishkaPay.Checkout, :metadata}

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)