Paddle.Coupon (paddlex v0.1.0) View Source

Coupon

Link to this section Summary

Functions

Create a new coupon for the given product or a checkout

Delete a given coupon and prevent it from being further used

List all coupons valid for a specified one-time product or subscription plan

Update an existing coupon in your account

Link to this section Types

Specs

t() :: %Paddle.Coupon{
  allowed_uses: pos_integer(),
  coupon: String.t(),
  description: String.t(),
  discount_amount: number(),
  discount_currency: String.t() | nil,
  discount_type: String.t(),
  expires: Date.t() | nil,
  is_recurring: boolean(),
  times_used: non_neg_integer()
}

Link to this section Functions

Link to this function

create(params, opts \\ [])

View Source

Specs

create(params, keyword()) :: {:ok, map()} | {:error, Paddle.Error.t()}
when params: %{
       optional(:coupon_code) => String.t(),
       optional(:coupon_prefix) => String.t(),
       optional(:num_coupons) => integer(),
       optional(:description) => String.t(),
       :coupon_type => String.t(),
       optional(:product_ids) => [number()],
       :discount_type => String.t(),
       :discount_amount => number(),
       optional(:currency) => String.t(),
       optional(:allowed_uses) => integer(),
       optional(:expires) => String.t(),
       optional(:recurring) => boolean(),
       optional(:group) => String.t()
     }

Create a new coupon for the given product or a checkout

Examples

params = %{
  coupon_prefix: "TEST",
  num_coupons: 5,
  description: "Test Coupon",
  coupon_type: "checkout",
  discount_type: "percentage",
  discount_amount: 10
}
Paddle.Coupon.create(params)  
{:ok, %{
    coupon_codes: [
      "TEST-03C532BD",
      "TEST-491AC84D",
      "TEST-899202BB",
      "TEST-96518CAF",
      "TEST-2A2A7594"
    ]
}}
Link to this function

delete(coupon_code, params \\ %{}, opts \\ [])

View Source

Specs

delete(String.t(), params, keyword()) ::
  {:ok, [t()]} | {:error, Paddle.Error.t()}
when params: %{optional(:product_id) => integer()}

Delete a given coupon and prevent it from being further used

Examples

Paddle.Coupon.delete("TEST") 
{:ok, nil}
Link to this function

list(product_id, opts \\ [])

View Source

Specs

list(integer(), keyword()) :: {:ok, [t()]} | {:error, Paddle.Error.t()}

List all coupons valid for a specified one-time product or subscription plan

Examples

Paddle.Coupon.list(1234)  
{:ok, [
  %Paddle.Coupon{
    coupon: "56604810a6990",
    description: "56604810a6dcd",
    discount_type: "percentage",
    discount_amount: 0.5,
    discount_currency: "USD",
    allowed_uses: 3,
    times_used: 2,
    is_recurring: true,
    expires: ~U"2020-12-03 00:00:00Z"
  }
]}
Link to this function

update(params, opts \\ [])

View Source

Specs

update(params, keyword()) :: {:ok, map()} | {:error, Paddle.Error.t()}
when params: %{
       optional(:coupon_code) => String.t(),
       optional(:group) => String.t(),
       optional(:new_coupon_code) => String.t(),
       optional(:new_group) => String.t(),
       optional(:product_ids) => String.t(),
       optional(:expires) => String.t(),
       optional(:allowed_uses) => integer(),
       optional(:currency) => String.t(),
       optional(:discount_amount) => number(),
       optional(:recurring) => boolean()
     }

Update an existing coupon in your account

There are 2 main ways to select which coupon(s) you want to update:

  • Updating a single coupon code? Specify coupon_code.
  • Updating a group of coupons? Specify their unique group name.

Examples

params = %{
  coupon_code: "TEST",
  discount_amount: 20
}
Paddle.Coupon.update(params)
{:ok, 1}