PaperTiger.Resources.PaymentMethod (PaperTiger v1.0.2)

Copy Markdown View Source

Handles PaymentMethod resource endpoints.

Endpoints

  • POST /v1/payment_methods - Create payment method
  • GET /v1/payment_methods/:id - Retrieve payment method
  • POST /v1/payment_methods/:id - Update payment method
  • DELETE /v1/payment_methods/:id - Delete payment method
  • GET /v1/payment_methods - List payment methods

PaymentMethod Object

%{
  id: "pm_...",
  object: "payment_method",
  created: 1234567890,
  type: "card",
  customer: "cus_...",
  metadata: %{},
  card: %{
    brand: "visa",
    last4: "4242",
    exp_month: 12,
    exp_year: 2025
  },
  billing_details: %{
    name: "John Doe",
    email: "john@example.com",
    phone: "+1234567890",
    address: %{
      country: "US",
      postal_code: "12345",
      state: "CA",
      city: "San Francisco",
      line1: "123 Main St",
      line2: nil
    }
  }
}

Summary

Functions

Attaches a payment method to a customer.

Creates a new payment method.

Deletes a payment method.

Detaches a payment method from a customer.

Lists payment methods for a customer.

Retrieves a payment method by ID.

Updates a payment method.

Functions

attach(conn, id)

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

Attaches a payment method to a customer.

POST /v1/payment_methods/:id/attach

Associates a payment method with a customer ID.

create(conn)

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

Creates a new payment method.

Required Parameters

  • type - Payment method type ("card", "us_bank_account", etc.)

Optional Parameters

  • id - Custom ID (must start with "pm_"). Useful for seeding deterministic data.
  • customer - Customer ID to associate with
  • metadata - Key-value metadata
  • card - Card details (when type=card)
  • billing_details - Billing address and contact info

delete(conn, id)

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

Deletes a payment method.

Returns a deletion confirmation object.

detach(conn, id)

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

Detaches a payment method from a customer.

POST /v1/payment_methods/:id/detach

Removes the association between a payment method and a customer.

list(conn)

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

Lists payment methods for a customer.

Stripe API requires customer parameter for listing payment methods.

Required Parameters

  • customer - Customer ID (required)

Optional Parameters

  • limit - Number of items (default: 10, max: 100)
  • starting_after - Cursor for pagination
  • ending_before - Reverse cursor
  • type - Filter by payment method type

retrieve(conn, id)

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

Retrieves a payment method by ID.

update(conn, id)

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

Updates a payment method.

Note: PaymentMethods can only have limited fields updated.

Updatable Fields

  • metadata
  • billing_details