View Source Stripe.Coupon (stripity_stripe v3.2.0)

A coupon contains information about a percent-off or amount-off discount you might want to apply to a customer. Coupons may be applied to subscriptions, invoices, checkout sessions, quotes, and more. Coupons do not work with conventional one-off charges or payment intents.

Summary

Types

A hash containing directions for what this Coupon will apply discounts to.

t()

The coupon type.

Functions

You can create coupons easily via the coupon management page of the Stripe dashboard. Coupon creation is also accessible via the API if you need to create coupons on the fly.

You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can’t redeem the coupon. You can also delete coupons via the API.

Returns a list of your coupons.

Retrieves the coupon with the given ID.

Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.

Types

@type applies_to() :: %{optional(:products) => [binary()]}

A hash containing directions for what this Coupon will apply discounts to.

@type created() :: %{
  optional(:gt) => integer(),
  optional(:gte) => integer(),
  optional(:lt) => integer(),
  optional(:lte) => integer()
}
@type t() :: %Stripe.Coupon{
  amount_off: integer() | nil,
  applies_to: term(),
  created: integer(),
  currency: binary() | nil,
  currency_options: term(),
  duration: binary(),
  duration_in_months: integer() | nil,
  id: binary(),
  livemode: boolean(),
  max_redemptions: integer() | nil,
  metadata: term() | nil,
  name: binary() | nil,
  object: binary(),
  percent_off: term() | nil,
  redeem_by: integer() | nil,
  times_redeemed: integer(),
  valid: boolean()
}

The coupon type.

  • amount_off Amount (in the currency specified) that will be taken off the subtotal of any invoices for this customer.
  • applies_to
  • created Time at which the object was created. Measured in seconds since the Unix epoch.
  • currency If amount_off has been set, the three-letter ISO code for the currency of the amount to take off.
  • currency_options Coupons defined in each available currency option. Each key must be a three-letter ISO currency code and a supported currency.
  • duration One of forever, once, and repeating. Describes how long a customer who applies this coupon will get the discount.
  • duration_in_months If duration is repeating, the number of months the coupon applies. Null if coupon duration is forever or once.
  • id Unique identifier for the object.
  • livemode Has the value true if the object exists in live mode or the value false if the object exists in test mode.
  • max_redemptions Maximum number of times this coupon can be redeemed, in total, across all customers, before it is no longer valid.
  • metadata Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  • name Name of the coupon displayed to customers on for instance invoices or receipts.
  • object String representing the object's type. Objects of the same type share the same value.
  • percent_off Percent that will be taken off the subtotal of any invoices for this customer for the duration of the coupon. For example, a coupon with percent_off of 50 will make a $ (or local equivalent)100 invoice $ (or local equivalent)50 instead.
  • redeem_by Date after which the coupon can no longer be redeemed.
  • times_redeemed Number of times this coupon has been applied to a customer.
  • valid Taking account of the above properties, whether this coupon can still be applied to a customer.

Functions

Link to this function

create(params \\ %{}, opts \\ [])

View Source
@spec create(
  params :: %{
    optional(:amount_off) => integer(),
    optional(:applies_to) => applies_to(),
    optional(:currency) => binary(),
    optional(:currency_options) => map(),
    optional(:duration) => :forever | :once | :repeating,
    optional(:duration_in_months) => integer(),
    optional(:expand) => [binary()],
    optional(:id) => binary(),
    optional(:max_redemptions) => integer(),
    optional(:metadata) => %{optional(binary()) => binary()} | binary(),
    optional(:name) => binary(),
    optional(:percent_off) => number(),
    optional(:redeem_by) => integer()
  },
  opts :: Keyword.t()
) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}

You can create coupons easily via the coupon management page of the Stripe dashboard. Coupon creation is also accessible via the API if you need to create coupons on the fly.

A coupon has either a percent_off or an amount_off and currency. If you set an amount_off, that amount will be subtracted from any invoice’s subtotal. For example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an amount_off of 200 is applied to it and an invoice with a subtotal of 300 will have a final total of 100 if a coupon with an amount_off of 200 is applied to it.

Details

  • Method: post
  • Path: /v1/coupons
Link to this function

delete(coupon, opts \\ [])

View Source
@spec delete(coupon :: binary(), opts :: Keyword.t()) ::
  {:ok, Stripe.DeletedCoupon.t()}
  | {:error, Stripe.ApiErrors.t()}
  | {:error, term()}

You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can’t redeem the coupon. You can also delete coupons via the API.

Details

  • Method: delete
  • Path: /v1/coupons/{coupon}
Link to this function

list(params \\ %{}, opts \\ [])

View Source
@spec list(
  params :: %{
    optional(:created) => created() | integer(),
    optional(:ending_before) => binary(),
    optional(:expand) => [binary()],
    optional(:limit) => integer(),
    optional(:starting_after) => binary()
  },
  opts :: Keyword.t()
) ::
  {:ok, Stripe.List.t(t())} | {:error, Stripe.ApiErrors.t()} | {:error, term()}

Returns a list of your coupons.

Details

  • Method: get
  • Path: /v1/coupons
Link to this function

retrieve(coupon, params \\ %{}, opts \\ [])

View Source
@spec retrieve(
  coupon :: binary(),
  params :: %{optional(:expand) => [binary()]},
  opts :: Keyword.t()
) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}

Retrieves the coupon with the given ID.

Details

  • Method: get
  • Path: /v1/coupons/{coupon}
Link to this function

update(coupon, params \\ %{}, opts \\ [])

View Source
@spec update(
  coupon :: binary(),
  params :: %{
    optional(:currency_options) => map(),
    optional(:expand) => [binary()],
    optional(:metadata) => %{optional(binary()) => binary()} | binary(),
    optional(:name) => binary()
  },
  opts :: Keyword.t()
) :: {:ok, t()} | {:error, Stripe.ApiErrors.t()} | {:error, term()}

Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.

Details

  • Method: post
  • Path: /v1/coupons/{coupon}