Version: v0.0.3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2020 License: BSD-2-Clause Imports: 8 Imported by: 0



Package coupon provides APIs related to coupons.



This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {

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) Delete

func (c Client) Delete(product int64, code string) error

Delete deletes the given coupon from the given product.

func (Client) List

func (c Client) List(productID int64) (Iter, error)

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.

func (Client) Update

func (c Client) Update(code string, coupon *Coupon) error

Update updates properties of a single coupon.

Empty values will be ignored. If products is nil, it will be ignored, if it is an empty slice, all products will be removed.

func (Client) UpdateGroup

func (c Client) UpdateGroup(group, newGroup string, coupon *Coupon) error

UpdateGroup updates properties of an entire group of coupons.

See UpdateCoupon for more information.

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

func (c *Coupon) UnmarshalJSON(b []byte) error

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.

type Iter

type Iter struct {
	// contains filtered or unexported fields

Iter provides a mechanism for lazily decoding and iterating over a list of coupons.

func (Iter) Decode

func (c Iter) Decode() (*Coupon, error)

Decode returns the next coupon.

func (Iter) Next

func (c Iter) Next() bool

Next returns true if there are more coupons to decode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL