MishkaPay.Providers.Stripe.TestClock (Mishka Pay v0.0.1)

Copy Markdown View Source

Stripe's test clocks, to see what time does to a subscription in a sandbox: a trial that ends, a renewal that is paid or fails, retries that run out. A customer made on a clock lives on its time; moving the clock forward makes Stripe run everything that would have happened by then.

{:ok, clock} = TestClock.create("site-a", name: "renewal test")
# make a customer with test_clock: clock.id, and a subscription for them
{:ok, clock} = TestClock.advance("site-a", clock.id, DateTime.add(clock.frozen_time, 32, :day))
# Stripe moves it on its own servers: read it until `status: :ready`, then read the
# subscription again (MishkaPay.fetch_subscription/3)

Only with a site's test keys: keys in :live mode, or a sk_live_ or rk_live_ key, are refused before any request. Each call takes the tenant whose keys to use.

Summary

Types

t()

The struct that builder/1 returns.

Functions

Moves clock id forward to to. Stripe answers at once with status: :advancing and moves it on its own servers; read it with fetch/2 until it is :ready.

Makes a clock frozen at :at (now by default), with an optional :name.

Deletes clock id, and with it every customer and subscription on it.

A sample %MishkaPay.Providers.Stripe.TestClock{} populated from defaults + type-based fallbacks.

Reads clock id again: its time and whether it has finished moving (:ready).

The site's clocks, newest first.

Types

t()

@type t() :: %MishkaPay.Providers.Stripe.TestClock{
  created_at: DateTime.t() | nil,
  frozen_time: DateTime.t() | nil,
  id: String.t(),
  name: String.t() | nil,
  status: (:ready | :advancing | :failed) | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:idString.t()yesvalidate(not_nil_value, string, not_empty)
:nameString.t() | nilnovalidate(string)
:frozen_timeDateTime.t() | nilnovalidate(struct)
:status:ready | :advancing | :failed | nilnovalidate(enum=Atom[ready::advancing::failed])
:created_atDateTime.t() | nilnovalidate(struct)

Functions

advance(tenant, id, to)

@spec advance(term(), String.t(), DateTime.t()) ::
  {:ok, t()} | {:error, Splode.Error.t()}

Moves clock id forward to to. Stripe answers at once with status: :advancing and moves it on its own servers; read it with fetch/2 until it is :ready.

builder(attrs_or_input, error \\ false)

create(tenant, opts \\ [])

@spec create(term(), keyword()) :: {:ok, t()} | {:error, Splode.Error.t()}

Makes a clock frozen at :at (now by default), with an optional :name.

delete(tenant, id)

@spec delete(term(), String.t()) :: :ok | {:error, Splode.Error.t()}

Deletes clock id, and with it every customer and subscription on it.

enforce_keys()

enforce_keys(field)

example()

A sample %MishkaPay.Providers.Stripe.TestClock{} populated from defaults + type-based fallbacks.

fetch(tenant, id)

@spec fetch(term(), String.t()) :: {:ok, t()} | {:error, Splode.Error.t()}

Reads clock id again: its time and whether it has finished moving (:ready).

keys()

keys(field)

list(tenant)

@spec list(term()) :: {:ok, [t()]} | {:error, Splode.Error.t()}

The site's clocks, newest first.