Documentation
¶
Overview ¶
Package coupon provides APIs related to coupons.
Index ¶
- type Client
- func (c Client) Create(num int, prefix, group string, couponType CouponType, recurring bool, ...) ([]string, error)
- func (c Client) Delete(product int64, code string) error
- func (c Client) List(productID int64) (Iter, error)
- func (c Client) Update(code string, coupon *Coupon) error
- func (c Client) UpdateGroup(group, newGroup string, coupon *Coupon) error
- type Coupon
- type CouponType
- type DiscountType
- type Iter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client performs API operations.
func (Client) Create ¶
func (c Client) Create(num int, prefix, group string, couponType CouponType, recurring bool, coupon *Coupon) ([]string, error)
Create creates a number of identical coupons. If num is greater than 1, coupon.Code is ignored and the codes are randomized. The coupon.Product field is ignored.
func (Client) List ¶
List requests a list of coupons available for the given product and returns an iterator that decodes them from the response body.
If an error is returned, it is decoded and returned immediately.
type Coupon ¶
type Coupon struct { ID int64 `json:"id"` Code string `json:"coupon"` Description string `json:"description"` DiscountType DiscountType `json:"discount_type"` DiscountAmount float64 `json:"discount_amount"` Currency paddle.Currency `json:"discount_currency"` AllowedUses int `json:"allowed_uses"` TimesUsed int `json:"times_used"` Recurring bool `json:"is_recurring"` Expires paddle.Time `json:"expires"` Product []int64 `json:"-"` Minimum float64 `json:"minimum_threshold"` }
Coupon represents a single coupon for a specific product.
func (*Coupon) UnmarshalJSON ¶
UnmarshalJSON satisfies the json.Unmarshaler interface for Coupon.
It is necessary because when creating coupons a slice of product IDs is required, but when getting coupons an individual product ID is provided. When unmarshaling, convert the indivdiual product ID into a slice of length 1.
type CouponType ¶
type CouponType string
CouponType is a specific type of coupon.
const ( CouponProduct CouponType = "product" CouponCheckout CouponType = "checkout" )
A list of valid coupon types.
type DiscountType ¶
type DiscountType string
DiscountType is a type of discount that can be applied with a coupon.
const ( DiscountFlat DiscountType = "flat" DiscountPercentage DiscountType = "percentage" )
A list of valid coupon types.