recurly v0.0.1 Recurly.Coupon
Module for handling coupons in Recurly. See the developer docs on coupons for more details
Summary
Functions
Creates a coupon from a changeset
Finds a coupon given a coupon code. Returns the coupon or an error
Lists all the coupons. See the couopons dev docs for more details
Generates the path to a coupon given the coupon code
Functions
Creates a coupon from a changeset.
Parameters
changeset
Keyword list changeset
Examples
alias Recurly.ValidationError
changeset = [
coupon_code: "mycouponcode",
name: "My Coupon",
discount_type: "dollars",
discount_in_cents: [
USD: 1000
],
duration: "single_use"
]
case Recurly.Coupon.create(changeset) do
{:ok, coupon} ->
# created the coupon
{:error, %ValidationError{errors: errors}} ->
# will give you a list of validation errors
end
Finds a coupon given a coupon code. Returns the coupon or an error.
Parameters
coupon_code
String coupon code
Examples
alias Recurly.NotFoundError
case Recurly.Coupon.find("mycouponcode") do
{:ok, coupon} ->
# Found the coupon
{:error, %NotFoundError{}} ->
# 404 coupon was not found
end
Lists all the coupons. See the couopons dev docs for more details.
Parameters
options
Keyword list of GET params
Examples
case Recurly.Coupon.list(state: "redeemable") do
{:ok, coupons} ->
# list of redeemable coupons
{:error, error} ->
# error happened
end