MishkaPay.SetupIntent (Mishka Pay v0.0.1)

Copy Markdown View Source

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.

Summary

Types

t()

The struct that builder/1 returns.

Functions

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

The statuses a setup intent can have.

Types

t()

@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.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:tenantterm() | nilno
:idString.t() | nilnosanitize(trim) validate(string, not_empty)
:customer_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:payment_method_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:usage:on_session | :off_session | nilnovalidate(enum=Atom[on_session::off_session])<br>validator {MishkaPay.PaymentIntent, :usage}
:automatic_payment_methodsboolean() | nilnovalidate(boolean)
:descriptionString.t() | nilnosanitize(trim) validate(string, max_len=1000)
:referenceString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=200)
:metadatamap() | nilno%{}validate(map)<br>validator {MishkaPay.Checkout, :metadata}
:client_secretString.t() | nilnovalidate(string)
:statusatom() | nilnovalidate(enum=Atom[requires_payment_method::requires_confirmation::requires_action::processing::succeeded::canceled])
:failure_codeString.t() | nilnovalidate(string)
:failure_messageString.t() | nilnovalidate(string)
:created_atDateTime.t() | nilnovalidate(struct)

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)

statuses()

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

The statuses a setup intent can have.