LatticeStripe.CreditNote (LatticeStripe v1.7.7)

Copy Markdown View Source

Operations on Stripe Credit Note objects.

Credit notes let you reduce the amount of an invoice after it has been finalized. This module exposes Stripe-shaped CRUDL, preview, void, and line-item access without adding a local builder or workflow abstraction.

Credit notes can only be created from finalized invoices. Previews use the same raw parameter shape as create, so the easiest way to validate a request is to send it through preview/3 first.

Common preview shapes

LatticeStripe.CreditNote.preview(client, %{
  "invoice" => "in_123",
  "lines" => [
    %{
      "type" => "invoice_line_item",
      "invoice_line_item" => "il_123",
      "quantity" => 1
    }
  ]
})

LatticeStripe.CreditNote.preview(client, %{
  "invoice" => "in_123",
  "lines" => [
    %{
      "type" => "custom_line_item",
      "description" => "Goodwill credit",
      "quantity" => 1,
      "unit_amount" => 500
    }
  ]
})

Summary

Functions

Creates a Credit Note.

Like create/3 but raises on failure.

Lists Credit Notes with optional filters.

Like list/3 but raises on failure.

Lists line items for an issued Credit Note.

Lists preview line items for a Credit Note preview request.

Previews a Credit Note without creating it.

Like preview/3 but raises on failure.

Retrieves a Credit Note by ID.

Like retrieve/3 but raises on failure.

Returns a lazy stream of Credit Notes matching the given filters.

Returns a lazy stream of line items for an issued Credit Note.

Returns a lazy stream of preview line items for a Credit Note preview request.

Updates a Credit Note by ID.

Voids a Credit Note.

Like void/3 but raises on failure.

Types

t()

@type t() :: %LatticeStripe.CreditNote{
  amount: integer() | nil,
  amount_shipping: integer() | nil,
  created: integer() | nil,
  currency: String.t() | nil,
  customer: LatticeStripe.Customer.t() | String.t() | nil,
  customer_balance_transaction:
    LatticeStripe.BalanceTransaction.t() | String.t() | nil,
  effective_at: integer() | nil,
  extra: map(),
  id: String.t() | nil,
  invoice: LatticeStripe.Invoice.t() | String.t() | nil,
  lines: LatticeStripe.List.t() | nil,
  livemode: boolean() | nil,
  memo: String.t() | nil,
  metadata: map() | nil,
  number: String.t() | nil,
  object: String.t(),
  out_of_band_amount: integer() | nil,
  pdf: String.t() | nil,
  post_payment_amount: integer() | nil,
  pre_payment_amount: integer() | nil,
  reason: atom() | String.t() | nil,
  refunds: list() | map() | nil,
  shipping_cost: map() | nil,
  status: atom() | String.t() | nil,
  subtotal: integer() | nil,
  subtotal_excluding_tax: integer() | nil,
  total: integer() | nil,
  total_excluding_tax: integer() | nil,
  total_taxes: list() | map() | nil,
  type: atom() | String.t() | nil,
  voided_at: integer() | nil
}

Functions

create(client, params, opts \\ [])

@spec create(LatticeStripe.Client.t(), map(), keyword()) ::
  {:ok, t()} | {:error, LatticeStripe.Error.t()}

Creates a Credit Note.

Sends POST /v1/credit_notes with the raw params map.

create!(client, params, opts \\ [])

@spec create!(LatticeStripe.Client.t(), map(), keyword()) :: t()

Like create/3 but raises on failure.

from_map(map)

@spec from_map(map() | nil) :: t() | nil

list(client, params \\ %{}, opts \\ [])

@spec list(LatticeStripe.Client.t(), map(), keyword()) ::
  {:ok, LatticeStripe.Response.t()} | {:error, LatticeStripe.Error.t()}

Lists Credit Notes with optional filters.

list!(client, params \\ %{}, opts \\ [])

Like list/3 but raises on failure.

list_line_items(client, id, params \\ %{}, opts \\ [])

@spec list_line_items(LatticeStripe.Client.t(), String.t(), map(), keyword()) ::
  {:ok, LatticeStripe.Response.t()} | {:error, LatticeStripe.Error.t()}

Lists line items for an issued Credit Note.

list_line_items!(client, id, params \\ %{}, opts \\ [])

@spec list_line_items!(LatticeStripe.Client.t(), String.t(), map(), keyword()) ::
  LatticeStripe.Response.t()

Like list_line_items/4 but raises on failure.

list_preview_line_items(client, params \\ %{}, opts \\ [])

@spec list_preview_line_items(LatticeStripe.Client.t(), map(), keyword()) ::
  {:ok, LatticeStripe.Response.t()} | {:error, LatticeStripe.Error.t()}

Lists preview line items for a Credit Note preview request.

list_preview_line_items!(client, params \\ %{}, opts \\ [])

@spec list_preview_line_items!(LatticeStripe.Client.t(), map(), keyword()) ::
  LatticeStripe.Response.t()

Like list_preview_line_items/3 but raises on failure.

preview(client, params, opts \\ [])

@spec preview(LatticeStripe.Client.t(), map(), keyword()) ::
  {:ok, t()} | {:error, LatticeStripe.Error.t()}

Previews a Credit Note without creating it.

The params shape matches create/3 exactly.

Example

LatticeStripe.CreditNote.preview(client, %{
  "invoice" => "in_123",
  "lines" => [
    %{
      "type" => "invoice_line_item",
      "invoice_line_item" => "il_123",
      "quantity" => 1
    },
    %{
      "type" => "custom_line_item",
      "description" => "Goodwill credit",
      "quantity" => 1,
      "unit_amount" => 500
    }
  ]
})

preview!(client, params, opts \\ [])

@spec preview!(LatticeStripe.Client.t(), map(), keyword()) :: t()

Like preview/3 but raises on failure.

retrieve(client, id, opts \\ [])

@spec retrieve(LatticeStripe.Client.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, LatticeStripe.Error.t()}

Retrieves a Credit Note by ID.

retrieve!(client, id, opts \\ [])

@spec retrieve!(LatticeStripe.Client.t(), String.t(), keyword()) :: t()

Like retrieve/3 but raises on failure.

stream!(client, params \\ %{}, opts \\ [])

@spec stream!(LatticeStripe.Client.t(), map(), keyword()) :: Enumerable.t()

Returns a lazy stream of Credit Notes matching the given filters.

stream_line_items!(client, id, params \\ %{}, opts \\ [])

@spec stream_line_items!(LatticeStripe.Client.t(), String.t(), map(), keyword()) ::
  Enumerable.t()

Returns a lazy stream of line items for an issued Credit Note.

stream_preview_line_items!(client, params \\ %{}, opts \\ [])

@spec stream_preview_line_items!(LatticeStripe.Client.t(), map(), keyword()) ::
  Enumerable.t()

Returns a lazy stream of preview line items for a Credit Note preview request.

update(client, id, params, opts \\ [])

@spec update(LatticeStripe.Client.t(), String.t(), map(), keyword()) ::
  {:ok, t()} | {:error, LatticeStripe.Error.t()}

Updates a Credit Note by ID.

Stripe currently only documents narrow mutable fields such as memo and metadata, but this function passes the raw params through unchanged.

update!(client, id, params, opts \\ [])

@spec update!(LatticeStripe.Client.t(), String.t(), map(), keyword()) :: t()

Like update/4 but raises on failure.

void(client, id, opts \\ [])

@spec void(LatticeStripe.Client.t(), String.t(), keyword()) ::
  {:ok, t()} | {:error, LatticeStripe.Error.t()}

Voids a Credit Note.

Sends POST /v1/credit_notes/:id/void with an empty body.

Irreversibility

Voiding is irreversible. Credit notes can only be created from finalized invoices, and voiding is only valid when the credit note is attached to an open invoice.

void!(client, id, opts \\ [])

@spec void!(LatticeStripe.Client.t(), String.t(), keyword()) :: t()

Like void/3 but raises on failure.