Current section

Files

Jump to
paper_tiger lib paper_tiger resources application_fee.ex
Raw

lib/paper_tiger/resources/application_fee.ex

defmodule PaperTiger.Resources.ApplicationFee do
@moduledoc """
Handles Application Fee resource endpoints.
## Endpoints
- GET /v1/application_fees/:id - Retrieve application fee
- GET /v1/application_fees - List application fees
Note: Application fees are auto-generated by Stripe and cannot be created, updated, or deleted.
## Application Fee Object
%{
id: "fee_...",
object: "application_fee",
created: 1234567890,
amount: 100, # in cents
currency: "usd",
charge: "ch_...",
refunded: false,
amount_refunded: 0,
metadata: %{},
# ... other fields
}
"""
import PaperTiger.Resource
alias PaperTiger.Store.ApplicationFees
require Logger
@doc """
Retrieves an application fee by ID.
"""
@spec retrieve(Plug.Conn.t(), String.t()) :: Plug.Conn.t()
def retrieve(conn, id) do
case ApplicationFees.get(id) do
{:ok, fee} ->
fee
|> maybe_expand(conn.params)
|> then(&json_response(conn, 200, &1))
{:error, :not_found} ->
error_response(conn, PaperTiger.Error.not_found("application_fee", id))
end
end
@doc """
Lists all application fees with pagination.
## Parameters
- limit - Number of items (default: 10, max: 100)
- starting_after - Cursor for pagination
- ending_before - Reverse cursor
- charge - Filter by charge ID
"""
@spec list(Plug.Conn.t()) :: Plug.Conn.t()
def list(conn) do
pagination_opts = parse_pagination_params(conn.params)
result = ApplicationFees.list(pagination_opts)
json_response(conn, 200, result)
end
## Private Functions
defp maybe_expand(fee, params) do
expand_params = parse_expand_params(params)
PaperTiger.Hydrator.hydrate(fee, expand_params)
end
end