PaperTiger.Resources.Charge (PaperTiger v1.0.2)

Copy Markdown View Source

Handles Charge resource endpoints.

Endpoints

  • POST /v1/charges - Create charge
  • GET /v1/charges/:id - Retrieve charge
  • POST /v1/charges/:id - Update charge
  • GET /v1/charges - List charges

Note: Charges cannot be deleted (immutable resource).

Charge Object

%{
  id: "ch_...",
  object: "charge",
  created: 1234567890,
  amount: 2000,  # in cents ($20.00)
  currency: "usd",
  status: "succeeded",
  customer: "cus_...",
  payment_method: "pm_...",
  metadata: %{},
  refunded: false,
  amount_refunded: 0,
  # ... other fields
}

Summary

Functions

Creates a new charge.

Lists all charges with pagination.

Retrieves a charge by ID.

Updates a charge.

Functions

create(conn)

@spec create(Plug.Conn.t()) :: Plug.Conn.t()

Creates a new charge.

Required Parameters

  • amount - Amount in cents (e.g., 2000 for $20.00)
  • currency - Three-letter ISO currency code (e.g., "usd")

Optional Parameters

  • customer - Customer ID
  • payment_method - Payment method ID
  • description - Charge description
  • metadata - Key-value metadata
  • statement_descriptor - Descriptor for bank statements

list(conn)

@spec list(Plug.Conn.t()) :: Plug.Conn.t()

Lists all charges with pagination.

Parameters

  • limit - Number of items (default: 10, max: 100)
  • starting_after - Cursor for pagination
  • ending_before - Reverse cursor
  • customer - Filter by customer ID
  • status - Filter by status (succeeded, pending, failed)

retrieve(conn, id)

@spec retrieve(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Retrieves a charge by ID.

update(conn, id)

@spec update(Plug.Conn.t(), String.t()) :: Plug.Conn.t()

Updates a charge.

Note: Charges can only have limited fields updated.

Updatable Fields

  • metadata
  • description