Packages
A production-grade, fully-typed Elixir client for the SumUp API (Checkouts, Readers, Customers, Transactions, Payouts, Receipts, Members, Memberships, Roles and Merchants) with telemetry, retries, cursor streaming, webhook handling, and RFC 9457 aware error handling.
Current section
Files
Jump to
Current section
Files
lib/sumup/receipts.ex
defmodule Sumup.Receipts do
@moduledoc """
Receipts: detailed, receipt-formatted view of a transaction, keyed by
transaction id plus the merchant id (`mid`). API version `v1.1`.
"""
alias Sumup.{Client, Config, Receipt}
@get_schema NimbleOptions.new!(
mid: [
type: :string,
required: true,
doc: "Merchant id/code that owns the transaction."
],
tx_event_id: [
type: :integer,
doc:
"Fetch the receipt for a specific refund/event rather than the original charge."
]
)
@doc """
Retrieves the receipt for a transaction by `transaction_id`.
#{NimbleOptions.docs(@get_schema)}
"""
@spec get(Config.t(), String.t(), keyword()) :: {:ok, Receipt.t()} | {:error, Sumup.Error.t()}
def get(%Config{} = config, transaction_id, opts) do
opts = NimbleOptions.validate!(opts, @get_schema)
with {:ok, body} <-
Client.request(config, :get, "/v1.1/receipts/#{transaction_id}",
query: Map.new(opts),
resource: :receipts,
operation: :get
) do
{:ok, Receipt.from_json(body)}
end
end
end