# `Polarex.Subscriptions`
[🔗](https://github.com/giusdp/polarex/blob/main/lib/polarex/operations/subscriptions.ex#L1)

Provides API endpoints related to subscriptions

# `customer_portal_subscriptions_cancel`

```elixir
@spec customer_portal_subscriptions_cancel(id :: String.t(), opts :: keyword()) ::
  {:ok, Polarex.CustomerSubscription.t()}
  | {:error,
     Polarex.AlreadyCanceledSubscription.t()
     | Polarex.HTTPValidationError.t()
     | Polarex.ResourceNotFound.t()}
```

Cancel Subscription

Cancel a subscription of the authenticated customer.

# `customer_portal_subscriptions_get`

```elixir
@spec customer_portal_subscriptions_get(id :: String.t(), opts :: keyword()) ::
  {:ok, Polarex.CustomerSubscription.t()}
  | {:error, Polarex.HTTPValidationError.t() | Polarex.ResourceNotFound.t()}
```

Get Subscription

Get a subscription for the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

# `customer_portal_subscriptions_list`

```elixir
@spec customer_portal_subscriptions_list(opts :: keyword()) ::
  {:ok, Polarex.ListResourceCustomerSubscription.t()}
  | {:error, Polarex.HTTPValidationError.t()}
```

List Subscriptions

List subscriptions of the authenticated customer.

**Scopes**: `customer_portal:read` `customer_portal:write`

## Options

  * `product_id`: Filter by product ID.
  * `active`: Filter by active or cancelled subscription.
  * `query`: Search by product or organization name.
  * `page`: Page number, defaults to 1.
  * `limit`: Size of a page, defaults to 10. Maximum is 100.
  * `sorting`: Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.

# `customer_portal_subscriptions_update`

```elixir
@spec customer_portal_subscriptions_update(
  id :: String.t(),
  body ::
    Polarex.CustomerSubscriptionCancel.t()
    | Polarex.CustomerSubscriptionUpdateClear.t()
    | Polarex.CustomerSubscriptionUpdateProduct.t()
    | Polarex.CustomerSubscriptionUpdateSeats.t(),
  opts :: keyword()
) ::
  {:ok, Polarex.CustomerSubscription.t()}
  | {:error,
     Polarex.AlreadyCanceledSubscription.t()
     | Polarex.HTTPValidationError.t()
     | Polarex.PaymentFailed.t()
     | Polarex.ResourceNotFound.t()}
```

Update Subscription

Update a subscription of the authenticated customer.

## Request Body

**Content Types**: `application/json`

# `subscriptions_create`

```elixir
@spec subscriptions_create(
  body ::
    Polarex.SubscriptionCreateCustomer.t()
    | Polarex.SubscriptionCreateExternalCustomer.t(),
  opts :: keyword()
) :: {:ok, Polarex.Subscription.t()} | {:error, Polarex.HTTPValidationError.t()}
```

Create Subscription

Create a subscription programmatically.

This endpoint only allows to create subscription on free products.
For paid products, use the checkout flow.

No initial order will be created and no confirmation email will be sent.

**Scopes**: `subscriptions:write`

## Request Body

**Content Types**: `application/json`

# `subscriptions_export`

```elixir
@spec subscriptions_export(opts :: keyword()) ::
  {:ok, map() | String.t()} | {:error, Polarex.HTTPValidationError.t()}
```

Export Subscriptions

Export subscriptions as a CSV file.

**Scopes**: `subscriptions:read` `subscriptions:write`

## Options

  * `organization_id`: Filter by organization ID.

# `subscriptions_get`

```elixir
@spec subscriptions_get(id :: String.t(), opts :: keyword()) ::
  {:ok, Polarex.Subscription.t()}
  | {:error, Polarex.HTTPValidationError.t() | Polarex.ResourceNotFound.t()}
```

Get Subscription

Get a subscription by ID.

**Scopes**: `subscriptions:read` `subscriptions:write`

# `subscriptions_list`

```elixir
@spec subscriptions_list(opts :: keyword()) ::
  {:ok, Polarex.ListResourceSubscription.t()}
  | {:error, Polarex.HTTPValidationError.t()}
```

List Subscriptions

List subscriptions.

**Scopes**: `subscriptions:read` `subscriptions:write`

## Options

  * `organization_id`: Filter by organization ID.
  * `product_id`: Filter by product ID.
  * `customer_id`: Filter by customer ID.
  * `external_customer_id`: Filter by customer external ID.
  * `discount_id`: Filter by discount ID.
  * `active`: Filter by active or inactive subscription.
  * `cancel_at_period_end`: Filter by subscriptions that are set to cancel at period end.
  * `customer_cancellation_reason`: Filter by customer cancellation reason.
  * `canceled_at_after`: Filter by cancellation date (after or equal to).
  * `canceled_at_before`: Filter by cancellation date (before or equal to).
  * `page`: Page number, defaults to 1.
  * `limit`: Size of a page, defaults to 10. Maximum is 100.
  * `sorting`: Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign `-` before the criteria name to sort by descending order.
  * `metadata`: Filter by metadata key-value pairs. It uses the `deepObject` style, e.g. `?metadata[key]=value`.

# `subscriptions_revoke`

```elixir
@spec subscriptions_revoke(id :: String.t(), opts :: keyword()) ::
  {:ok, Polarex.Subscription.t()}
  | {:error,
     Polarex.AlreadyCanceledSubscription.t()
     | Polarex.HTTPValidationError.t()
     | Polarex.ResourceNotFound.t()
     | Polarex.SubscriptionLocked.t()}
```

Revoke Subscription

Revoke a subscription, i.e cancel immediately.

**Scopes**: `subscriptions:write`

# `subscriptions_update`

```elixir
@spec subscriptions_update(
  id :: String.t(),
  body ::
    Polarex.SubscriptionCancel.t()
    | Polarex.SubscriptionRevoke.t()
    | Polarex.SubscriptionUpdateBillingPeriod.t()
    | Polarex.SubscriptionUpdateClear.t()
    | Polarex.SubscriptionUpdateDiscount.t()
    | Polarex.SubscriptionUpdateProduct.t()
    | Polarex.SubscriptionUpdateSeats.t()
    | Polarex.SubscriptionUpdateTrial.t(),
  opts :: keyword()
) ::
  {:ok, Polarex.Subscription.t()}
  | {:error,
     Polarex.AlreadyCanceledSubscription.t()
     | Polarex.HTTPValidationError.t()
     | Polarex.PaymentFailed.t()
     | Polarex.ResourceNotFound.t()
     | Polarex.SubscriptionLocked.t()}
```

Update Subscription

Update a subscription.

**Scopes**: `subscriptions:write`

## Request Body

**Content Types**: `application/json`

---

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