# `PaperTiger.Resources.PaymentMethod`
[🔗](https://github.com/EnaiaInc/paper_tiger/blob/v1.2.2/lib/paper_tiger/resources/payment_method.ex#L1)

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
        }
      }
    }

# `attach`

```elixir
@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`

```elixir
@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`

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

Deletes a payment method.

Returns a deletion confirmation object.

# `detach`

```elixir
@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`

```elixir
@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`

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

Retrieves a payment method by ID.

# `update`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
