~samwhited/paddle

c565cafb1b99ab7ce52fad8cae0e3ea263fcd049 — Sam Whited 2 years ago 666247b
paddle, coupons: add new Currency type
2 files changed, 26 insertions(+), 14 deletions(-)

M coupon/coupons.go
A currency.go
M coupon/coupons.go => coupon/coupons.go +14 -14
@@ 72,7 72,7 @@ func (c Client) Create(num int, prefix, group string, couponType CouponType, rec
	v.Add("discount_type", string(coupon.DiscountType))
	v.Add("discount_amount", strconv.FormatFloat(coupon.DiscountAmount, 'f', -1, 64))
	if coupon.Currency != "" {
		v.Add("currency", coupon.Currency)
		v.Add("currency", string(coupon.Currency))
	}
	v.Add("allowed_uses", strconv.Itoa(coupon.AllowedUses))
	v.Add("expires", time.Time(coupon.Expires).Format(internal.DateFmt))


@@ 136,7 136,7 @@ func (c Client) updateCoupons(typ, code, newCode string, coupon *Coupon) error {
	}
	if coupon.DiscountType != "" {
		if coupon.DiscountType == DiscountFlat {
			v.Add("currency", coupon.Currency)
			v.Add("currency", string(coupon.Currency))
		}
		v.Add("discount_amount", strconv.FormatFloat(coupon.DiscountAmount, 'f', -1, 64))
	}


@@ 175,18 175,18 @@ func (c Iter) Decode() (*Coupon, error) {

// Coupon represents a single coupon for a specific product.
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       string       `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"`
	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"`
}

var _ json.Unmarshaler = (*Coupon)(nil)

A currency.go => currency.go +12 -0
@@ 0,0 1,12 @@
package paddle

// Currency is an ISO 4217 currency designator.
type Currency string

// Reexport of currencies currently supported by Paddle.
const (
	// G10 currencies
	USD Currency = "USD"

	// TODO:
)