Paypal.Subscription.Plan (Paypal v0.2.0)

Copy Markdown View Source

Manage billing plans for PayPal Subscriptions.

A billing plan defines the pricing, billing cycles, and payment preferences for a recurring subscription.

Official PayPal API Documentation: PayPal Billing Plans API v1

Summary

Functions

Activate a billing plan by ID.

Create a billing plan.

Deactivate a billing plan by ID.

List billing plans with optional filters.

Show billing plan details by plan ID.

Billing plan statuses

Update a billing plan by ID using JSON Patch operations.

Update pricing schemes for a plan by ID.

Functions

activate(plan_id)

@spec activate(String.t()) :: :ok | {:error, Paypal.Common.Error.t() | term()}

Activate a billing plan by ID.

Official documentation: Activate Plan

create(params)

@spec create(map()) ::
  {:ok, Paypal.Subscription.Plan.Info.t()}
  | {:error, Paypal.Common.Error.t() | term()}

Create a billing plan.

Official documentation: Create Plan

Examples

iex> Paypal.Subscription.Plan.create(%{
...>   product_id: "PROD-123",
...>   name: "Monthly Premium Plan",
...>   description: "Monthly subscription plan",
...>   status: :active,
...>   billing_cycles: [
...>     %{
...>       frequency: %{"interval_unit" => "MONTH", "interval_count" => 1},
...>       tenure_type: :regular,
...>       sequence: 1,
...>       total_cycles: 0,
...>       pricing_scheme: %{"fixed_price" => %{"currency_code" => "USD", "value" => "10.00"}}
...>     }
...>   ],
...>   payment_preferences: %{
...>     auto_bill_outstanding: true,
...>     setup_fee_failure_action: :cancel,
...>     payment_failure_threshold: 3
...>   }
...> })
{:ok, %Paypal.Subscription.Plan.Info{id: "P-123", ...}}

deactivate(plan_id)

@spec deactivate(String.t()) :: :ok | {:error, Paypal.Common.Error.t() | term()}

Deactivate a billing plan by ID.

Official documentation: Deactivate Plan

list(opts \\ [])

@spec list(keyword() | map()) ::
  {:ok, Paypal.Subscription.Plan.List.t()}
  | {:error, Paypal.Common.Error.t() | term()}

List billing plans with optional filters.

Official documentation: List Plans

Options

  • :product_id - Filter by product ID.
  • :plan_ids - Filter by specific plan IDs (comma-separated).
  • :page_size - Number of items per page (1 to 20, default 10).
  • :page - Page number (default 1).
  • :total_required - Whether total items count is returned (true or false).

show(plan_id)

@spec show(String.t()) ::
  {:ok, Paypal.Subscription.Plan.Info.t()}
  | {:error, Paypal.Common.Error.t() | term()}

Show billing plan details by plan ID.

Official documentation: Show Plan Details

statuses()

@spec statuses() :: [created: String.t(), inactive: String.t(), active: String.t()]

Billing plan statuses:

  • :created - Plan created but not active.
  • :inactive - Plan inactive (cannot be used for new subscriptions).
  • :active - Plan active and ready for subscriptions.

update(plan_id, patch_operations)

@spec update(String.t(), [map()]) :: :ok | {:error, Paypal.Common.Error.t() | term()}

Update a billing plan by ID using JSON Patch operations.

Official documentation: Update Plan

update_pricing_schemes(plan_id, pricing_schemes)

@spec update_pricing_schemes(String.t(), map() | [map()]) ::
  :ok | {:error, Paypal.Common.Error.t() | term()}

Update pricing schemes for a plan by ID.

Official documentation: Update Pricing Schemes