lemonsqueezy

package module
v0.0.0-...-8e198e2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 13 Imported by: 0

README

lemonsqueezy-go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a go API client for the lemonsqueezy API

Installation

lemonsqueezy-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/nightwolf93/lemonsqueezy-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/nightwolf93/lemonsqueezy-go"

Implemented

  • Users
    • GET /v1/users/me: Retrieves the currently authenticated user.
  • Stores
    • GET /v1/stores/:id: Retrieve a store
    • GET /v1/stores: List all stores
  • Customers
    • GET /v1/customers/:id: Retrieve a customer
    • GET /v1/customers: List all customers
  • Products
    • GET /v1/products/:id: Retrieve a product
    • GET /v1/products: List all products
  • Variants
    • GET /v1/variants/:id: Retrieve a variant
    • GET /v1/variants: List all variants
  • Prices
    • GET /v1/prices/:id: Retrieve a price
    • GET /v1/prices: List all prices
  • Files
    • GET /v1/files/:id: Retrieve a file
    • GET /v1/files: List all files
  • Orders
    • GET /v1/orders/:id: Retrieve an order
    • GET /v1/orders: List all orders
  • Order Items
    • GET /v1/order-items/:id: Retrieve an order item
    • GET /v1/order-items: List all order items
  • Subscriptions
    • PATCH /v1/subscriptions/:id: Update a subscription
    • GET /v1/subscriptions/:id: Retrieve a subscription
    • GET /v1/subscriptions: List all subscriptions
    • DELETE /v1/subscriptions/{id}: Cancel an active subscription
  • Subscription Invoices
    • GET /v1/subscription-invoices/:id: Retrieve a subscription invoice
    • GET /v1/subscription-invoices: List all subscription invoices
  • Subscription Items
    • GET /v1/subscription-items/:id: Retrieve a subscription item
    • PATCH /v1/subscription-items/:id: Update a subscription item
    • GET /v1/subscription-items: List all subscription items
    • GET /v1/subscription-items/:id/current-usage: Retrieve a subscription item's current usage
  • Discounts
    • POST /v1/discounts: Create a discount
    • GET /v1/discounts/:id: Retrieve a discount
    • DELETE /v1/discounts/:id: Delete a discount
    • GET /v1/discounts: List all discounts
  • Discount Redemptions
    • GET /v1/discount-redemptions/:id: Retrieve a discount redemption
    • GET /v1/discount-redemptions: List all discount redemptions
  • License Keys
    • GET /v1/license-keys/:id: Retrieve a license key
    • GET /v1/license-keys: List all license keys
  • License Key Instances
    • GET /v1/license-key-instances/:id: Retrieve a license key instance
    • GET /v1/license-key-instances: List all license keys instance
  • Licenses
    • POST /v1/licenses/validate: Validate a license
    • POST /v1/licenses/activate: Activate a license
    • POST /v1/licenses/deactivate: Deactivate a license
  • Checkouts
    • POST /v1/checkouts: Create a checkout
    • GET /v1/checkouts/:id: Retrieve a checkout
    • GET /v1/checkouts: List all checkouts
  • Webhooks
    • PATCH /v1/webhooks/:id: Update a webhook
    • GET /v1/webhooks/:id: Retrieve a webhook
    • GET /v1/webhooks: List all webhooks
    • DELETE /v1/webhooks/{id}: Update a webhook
    • Verify: Verify that webhook requests are coming from Lemon Squeezy

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
    "github.com/nightwolf93/lemonsqueezy-go"
)

func main() {
    client := lemonsqueezy.New(lemonsqueezy.WithAPIKey(""))
}
Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

subscription, response, err := client.Subscriptions.Get(context.Background(), "1")
if err != nil {
    //handle error
}
WebHooks

Webhooks allow Lemon Squeezy to send new data to your application when certain events occur inside your store. You can use the sample code below as inspiration for a basic http.HandlerFunc which processes webhook events on your server.

func WebhookHandler(_ http.ResponseWriter, req *http.Request) {

	// 1. Authenticate the webhook request from Lemon Squeezy using the `X-Signature` header

	// 2. Process the payload if the request is authenticated
	eventName := req.Header.Get("X-Event-Name")
	payload, err := io.ReadAll(req.Body)
	if err != nil {
		log.Fatal(err)
	}

	switch eventName {
	case lemonsqueezy.WebhookEventSubscriptionCreated:
		var request lemonsqueezy.WebhookRequestSubscription
		if err = json.Unmarshal(payload, &request); err != nil {
			log.Fatal(err)
		}
		// handle subscription_created request
	case lemonsqueezy.WebhookEventOrderCreated:
		var request lemonsqueezy.WebhookRequestOrder
		if err = json.Unmarshal(payload, &request); err != nil {
			log.Fatal(err)
		}
		// handle order_created request
	default:
		log.Fatal(fmt.Sprintf("invalid event [%s] received with request [%s]", eventName, string(payload)))
	}
}

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details

Documentation

Index

Constants

View Source
const (
	// WebhookEventOrderCreated occurs when a new order is successfully placed.
	WebhookEventOrderCreated = "order_created"

	// WebhookEventOrderRefunded occurs when a full or partial refund is made on an order.
	WebhookEventOrderRefunded = "order_refunded"

	// WebhookEventSubscriptionCreated occurs when a new subscription is successfully created.
	WebhookEventSubscriptionCreated = "subscription_created"

	// WebhookEventSubscriptionUpdated occurs when a subscription's data is changed or updated.
	WebhookEventSubscriptionUpdated = "subscription_updated"

	// WebhookEventSubscriptionCancelled occurs when a subscription is cancelled manually by the customer or store owner.
	WebhookEventSubscriptionCancelled = "subscription_cancelled"

	// WebhookEventSubscriptionResumed occurs when a subscription is resumed after being previously cancelled.
	WebhookEventSubscriptionResumed = "subscription_resumed"

	// WebhookEventSubscriptionExpired occurs when a subscription has ended after being previously cancelled, or once dunning has been completed for past_due subscriptions.
	WebhookEventSubscriptionExpired = "subscription_expired"

	// WebhookEventSubscriptionPaused occurs when a subscription's payment collection is paused.
	WebhookEventSubscriptionPaused = "subscription_paused"

	// WebhookEventSubscriptionUnpaused occurs when a subscription's payment collection is resumed after being previously paused.
	WebhookEventSubscriptionUnpaused = "subscription_unpaused"

	// WebhookEventSubscriptionPaymentSuccess occurs when a subscription payment is successful.
	WebhookEventSubscriptionPaymentSuccess = "subscription_payment_success"

	// WebhookEventSubscriptionPaymentFailed occurs when a subscription renewal payment fails.
	WebhookEventSubscriptionPaymentFailed = "subscription_payment_failed"

	// WebhookEventSubscriptionPaymentRecovered occurs when a subscription has a successful payment after a failed payment.
	WebhookEventSubscriptionPaymentRecovered = "subscription_payment_recovered"

	// WebhookEventSubscriptionPaymentRefunded occurs when a subscription payment is refunded.
	WebhookEventSubscriptionPaymentRefunded = "subscription_payment_refunded"

	// WebhookEventLicenseKeyCreated occurs when a license key is created from a new order.
	WebhookEventLicenseKeyCreated = "license_key_created"

	// WebhookEventLicenseKeyUpdated occurs when a license key is updated.
	WebhookEventLicenseKeyUpdated = "license_key_updated"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponseRelationshipsPrice

type APIResponseRelationshipsPrice struct {
	Variant ApiResponseLinks `json:"variant"`
}

APIResponseRelationshipsPrice relationships of a variant

type APIResponseRelationshipsVariant

type APIResponseRelationshipsVariant struct {
	Product ApiResponseLinks `json:"product"`
}

APIResponseRelationshipsVariant relationships of a variant

type ApiResponse

type ApiResponse[T any, R any] struct {
	Jsonapi ApiResponseJSONAPI    `json:"jsonapi"`
	Links   ApiResponseSelfLink   `json:"links"`
	Data    ApiResponseData[T, R] `json:"data"`
}

ApiResponse represents an API response

type ApiResponseData

type ApiResponseData[T any, R any] struct {
	Type          string              `json:"type"`
	ID            string              `json:"id"`
	Attributes    T                   `json:"attributes"`
	Relationships R                   `json:"relationships"`
	Links         ApiResponseSelfLink `json:"links"`
}

ApiResponseData contains the api response data

type ApiResponseDataWithoutRelationships

type ApiResponseDataWithoutRelationships[T any] struct {
	Type       string              `json:"type"`
	ID         string              `json:"id"`
	Attributes T                   `json:"attributes"`
	Links      ApiResponseSelfLink `json:"links"`
}

ApiResponseDataWithoutRelationships contains the api response data without any relationships

type ApiResponseJSONAPI

type ApiResponseJSONAPI struct {
	Version string `json:"version"`
}

ApiResponseJSONAPI API version

type ApiResponseLink struct {
	Related string `json:"related,omitempty"`
	Self    string `json:"self"`
}

ApiResponseLink defines a link

type ApiResponseLinks struct {
	Links ApiResponseLink `json:"links"`
}

ApiResponseLinks contains links to related resources

type ApiResponseList

type ApiResponseList[T any, R any] struct {
	Jsonapi ApiResponseJSONAPI      `json:"jsonapi"`
	Links   ApiResponseListLink     `json:"links"`
	Meta    ApiResponseListMeta     `json:"meta"`
	Data    []ApiResponseData[T, R] `json:"data"`
}

ApiResponseList represents an API response with a list of items

type ApiResponseListLink struct {
	First string  `json:"first"`
	Last  string  `json:"last"`
	Next  *string `json:"next"`
}

ApiResponseListLink defines a link for list os resources

type ApiResponseListMeta

type ApiResponseListMeta struct {
	Page ApiResponseListMetaPage `json:"page"`
}

ApiResponseListMeta defines the meta data for a list api response

type ApiResponseListMetaPage

type ApiResponseListMetaPage struct {
	CurrentPage int `json:"currentPage"`
	From        int `json:"from"`
	LastPage    int `json:"lastPage"`
	PerPage     int `json:"perPage"`
	To          int `json:"to"`
	Total       int `json:"total"`
}

ApiResponseListMetaPage defines the pagination meta data for a list api response

type ApiResponseMetaSubscriptionItemCurrentUsage

type ApiResponseMetaSubscriptionItemCurrentUsage struct {
	PeriodStart      time.Time `json:"period_start"`
	PeriodEnd        time.Time `json:"period_end"`
	Quantity         int       `json:"quantity"`
	IntervalUnit     string    `json:"interval_unit"`
	IntervalQuantity int       `json:"interval_quantity"`
}

type ApiResponseRelationshipWebhook

type ApiResponseRelationshipWebhook struct {
	Store ApiResponseLinks `json:"store"`
}

ApiResponseRelationshipWebhook relationships of a webhook

type ApiResponseRelationshipsCheckout

type ApiResponseRelationshipsCheckout struct {
	Store   ApiResponseLinks `json:"store"`
	Variant ApiResponseLinks `json:"variant"`
}

ApiResponseRelationshipsCheckout relationships of a checkout

type ApiResponseRelationshipsCustomer

type ApiResponseRelationshipsCustomer struct {
	Store         ApiResponseLinks `json:"store"`
	Subscriptions ApiResponseLinks `json:"subscriptions"`
	Orders        ApiResponseLinks `json:"orders"`
	LicenseKeys   ApiResponseLinks `json:"license-keys"`
}

ApiResponseRelationshipsCustomer relationships of a customer

type ApiResponseRelationshipsDiscount

type ApiResponseRelationshipsDiscount struct {
	Store               ApiResponseLinks `json:"store"`
	DiscountRedemptions ApiResponseLinks `json:"discount-redemptions"`
	Variants            ApiResponseLinks `json:"variants"`
}

ApiResponseRelationshipsDiscount relationships of a discount

type ApiResponseRelationshipsDiscountRedemption

type ApiResponseRelationshipsDiscountRedemption struct {
	Discount ApiResponseLinks `json:"discount"`
	Order    ApiResponseLinks `json:"order"`
}

ApiResponseRelationshipsDiscountRedemption relationships of a discount redemption

type ApiResponseRelationshipsFile

type ApiResponseRelationshipsFile struct {
	Variant ApiResponseLinks `json:"variant"`
}

ApiResponseRelationshipsFile relationships of a file

type ApiResponseRelationshipsLicenseKey

type ApiResponseRelationshipsLicenseKey struct {
	Store               ApiResponseLinks `json:"store"`
	Customer            ApiResponseLinks `json:"customer"`
	Order               ApiResponseLinks `json:"order"`
	OrderItem           ApiResponseLinks `json:"order-item"`
	Product             ApiResponseLinks `json:"product"`
	LicenseKeyInstances ApiResponseLinks `json:"license-key-instances"`
}

ApiResponseRelationshipsLicenseKey relationships of a license key

type ApiResponseRelationshipsLicenseKeyInstance

type ApiResponseRelationshipsLicenseKeyInstance struct {
	LicenseKey ApiResponseLinks `json:"license-key"`
}

ApiResponseRelationshipsLicenseKeyInstance relationships of a license key

type ApiResponseRelationshipsOrder

type ApiResponseRelationshipsOrder struct {
	Store               ApiResponseLinks `json:"store"`
	Customer            ApiResponseLinks `json:"customer"`
	OrderItems          ApiResponseLinks `json:"order-items"`
	Subscriptions       ApiResponseLinks `json:"subscriptions"`
	LicenseKeys         ApiResponseLinks `json:"license-keys"`
	DiscountRedemptions ApiResponseLinks `json:"discount-redemptions"`
}

ApiResponseRelationshipsOrder relationships of an order

type ApiResponseRelationshipsOrderItem

type ApiResponseRelationshipsOrderItem struct {
	Order   ApiResponseLinks `json:"order"`
	Product ApiResponseLinks `json:"product"`
	Variant ApiResponseLinks `json:"variant"`
}

ApiResponseRelationshipsOrderItem relationships of an order-item

type ApiResponseRelationshipsProduct

type ApiResponseRelationshipsProduct struct {
	Store    ApiResponseLinks `json:"store"`
	Variants ApiResponseLinks `json:"variants"`
}

ApiResponseRelationshipsProduct relationships of a product

type ApiResponseRelationshipsStore

type ApiResponseRelationshipsStore struct {
	Subscriptions ApiResponseLinks `json:"subscriptions"`
	Orders        ApiResponseLinks `json:"orders"`
	Products      ApiResponseLinks `json:"products"`
	LicenseKeys   ApiResponseLinks `json:"license-keys"`
	Discounts     ApiResponseLinks `json:"discounts"`
}

ApiResponseRelationshipsStore relationships of a store object

type ApiResponseRelationshipsSubscription

type ApiResponseRelationshipsSubscription struct {
	Store                ApiResponseLinks `json:"store"`
	Customer             ApiResponseLinks `json:"customer"`
	Order                ApiResponseLinks `json:"order"`
	OrderItem            ApiResponseLinks `json:"order-item"`
	Product              ApiResponseLinks `json:"product"`
	Variant              ApiResponseLinks `json:"variant"`
	SubscriptionItems    ApiResponseLinks `json:"subscription-items"`
	SubscriptionInvoices ApiResponseLinks `json:"subscription-invoices"`
}

ApiResponseRelationshipsSubscription relationships of a subscription object

type ApiResponseRelationshipsSubscriptionInvoice

type ApiResponseRelationshipsSubscriptionInvoice struct {
	Store        ApiResponseLinks `json:"store"`
	Subscription ApiResponseLinks `json:"subscription"`
}

ApiResponseRelationshipsSubscriptionInvoice relationships of a subscription invoice

type ApiResponseRelationshipsSubscriptionItem

type ApiResponseRelationshipsSubscriptionItem struct {
	Subscription ApiResponseLinks `json:"subscription"`
	Price        ApiResponseLinks `json:"price"`
	UsageRecords ApiResponseLinks `json:"usage-records"`
}

ApiResponseRelationshipsSubscription relationships of a subscription item object

type ApiResponseSelfLink struct {
	Self string `json:"self"`
}

ApiResponseSelfLink defines a link

type ApiResponseWithoutRelationships

type ApiResponseWithoutRelationships[T any] struct {
	Jsonapi ApiResponseJSONAPI                     `json:"jsonapi"`
	Links   ApiResponseSelfLink                    `json:"links"`
	Data    ApiResponseDataWithoutRelationships[T] `json:"data"`
}

ApiResponseWithoutRelationships represents an API response without relationships

type BillingAddress

type BillingAddress struct {
	Country string `json:"country"`
	Zip     string `json:"zip"`
}

BillingAddress contains the checkout billing address

type CheckoutApiResponse

CheckoutApiResponse is the api response for one checkout

type CheckoutAttributes

type CheckoutAttributes struct {
	StoreID         int                    `json:"store_id"`
	VariantID       int                    `json:"variant_id"`
	CustomPrice     interface{}            `json:"custom_price"`
	ProductOptions  CheckoutProductOptions `json:"product_options"`
	CheckoutOptions CheckoutOptions        `json:"checkout_options"`
	CheckoutData    CheckoutData           `json:"checkout_data"`
	ExpiresAt       *time.Time             `json:"expires_at"`
	CreatedAt       time.Time              `json:"created_at"`
	UpdatedAt       time.Time              `json:"updated_at"`
	TestMode        bool                   `json:"test_mode"`
	URL             string                 `json:"url"`
}

CheckoutAttributes contains information about a percentage or amount discount that can be applied to an order at checkout via a code.

type CheckoutCreateAttributes

type CheckoutCreateAttributes struct {
	CustomPrice     *int                         `json:"custom_price,omitempty"`
	ProductOptions  CheckoutCreateProductOptions `json:"product_options,omitempty"`
	CheckoutOptions CheckoutCreateOptions        `json:"checkout_options,omitempty"`
	CheckoutData    CheckoutCreateData           `json:"checkout_data,omitempty"`
	Preview         *bool                        `json:"preview,omitempty"`
	TestMode        *bool                        `json:"test_mode,omitempty"`
	ExpiresAt       *time.Time                   `json:"expires_at,omitempty"`
}

CheckoutCreateAttributes represents individual parameters for creating a checkout.

type CheckoutCreateData

type CheckoutCreateData struct {
	Email                 string                       `json:"email,omitempty"`
	Name                  string                       `json:"name,omitempty"`
	BillingAddressCountry string                       `json:"billing_address.country,omitempty"`
	BillingAddressZip     string                       `json:"billing_address.zip,omitempty"`
	TaxNumber             string                       `json:"tax_number,omitempty"`
	DiscountCode          string                       `json:"discount_code,omitempty"`
	Custom                []any                        `json:"custom,omitempty"`
	VariantQuantities     []CheckoutCreateDataQuantity `json:"variant_quantities,omitempty"`
}

CheckoutCreateData represents the data options for creating a checkout.

type CheckoutCreateDataQuantity

type CheckoutCreateDataQuantity struct {
	VariantId int `json:"variant_id"`
	Quantity  int `json:"quantity"`
}

CheckoutCreateDataQuantity represents variant quantities when creating checkout

type CheckoutCreateOptions

type CheckoutCreateOptions struct {
	Embed               *bool  `json:"embed,omitempty"`
	Media               *bool  `json:"media,omitempty"`
	Desc                *bool  `json:"desc,omitempty"`
	Discount            *bool  `json:"discount,omitempty"`
	Dark                *bool  `json:"dark,omitempty"`
	SubscriptionPreview *bool  `json:"subscription_preview,omitempty"`
	ButtonColor         string `json:"button_color,omitempty"`
}

CheckoutCreateOptions represents the checkout options for creating a checkout.

Note: We use pointers for the boolean fields as otherwise, setting them to "false" would omit them, which would break some of the boolean checks in the API. See: https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout

type CheckoutCreateProductOptions

type CheckoutCreateProductOptions struct {
	Name                string   `json:"name,omitempty"`
	Description         string   `json:"description,omitempty"`
	Media               []string `json:"media,omitempty"`
	RedirectUrl         string   `json:"redirect_url,omitempty"`
	ReceiptButtonText   string   `json:"receipt_button_text,omitempty"`
	ReceiptLinkUrl      string   `json:"receipt_link_url,omitempty"`
	ReceiptThankYouNote string   `json:"receipt_thank_you_note,omitempty"`
	EnabledVariants     []int    `json:"enabled_variants,omitempty"`
}

CheckoutCreateProductOptions represents product options for creating a checkout.

type CheckoutData

type CheckoutData struct {
	Email          string           `json:"email"`
	Name           string           `json:"name"`
	BillingAddress []BillingAddress `json:"billing_address"`
	TaxNumber      string           `json:"tax_number"`
	DiscountCode   string           `json:"discount_code"`
	Custom         []any            `json:"custom"`
}

CheckoutData contains information about a checkout

type CheckoutOptions

type CheckoutOptions struct {
	Embed               bool   `json:"embed"`
	Media               bool   `json:"media"`
	Desc                bool   `json:"desc"`
	Discount            bool   `json:"discount"`
	Dark                bool   `json:"dark"`
	SubscriptionPreview bool   `json:"subscription_preview"`
	ButtonColor         string `json:"button_color"`
}

CheckoutOptions are options for a checkout

type CheckoutPreview

type CheckoutPreview struct {
	Currency               string `json:"currency"`
	CurrencyRate           int    `json:"currency_rate"`
	Subtotal               int    `json:"subtotal"`
	DiscountTotal          int    `json:"discount_total"`
	Tax                    int    `json:"tax"`
	Total                  int    `json:"total"`
	SubtotalUsd            int    `json:"subtotal_usd"`
	DiscountTotalUsd       int    `json:"discount_total_usd"`
	TaxUsd                 int    `json:"tax_usd"`
	TotalUsd               int    `json:"total_usd"`
	SubtotalFormatted      string `json:"subtotal_formatted"`
	DiscountTotalFormatted string `json:"discount_total_formatted"`
	TaxFormatted           string `json:"tax_formatted"`
	TotalFormatted         string `json:"total_formatted"`
}

CheckoutPreview contains information about a percentage or amount discount that can be applied to an order at checkout via a code.

type CheckoutProductOptions

type CheckoutProductOptions struct {
	Name                string `json:"name"`
	Description         string `json:"description"`
	Media               []any  `json:"media"`
	RedirectURL         string `json:"redirect_url"`
	ReceiptButtonText   string `json:"receipt_button_text"`
	ReceiptLinkURL      string `json:"receipt_link_url"`
	ReceiptThankYouNote string `json:"receipt_thank_you_note"`
	EnabledVariants     []int  `json:"enabled_variants"`
}

CheckoutProductOptions are options for a checkout product

type CheckoutsApiResponse

CheckoutsApiResponse is the api response for a list of checkout.

type CheckoutsService

type CheckoutsService service

CheckoutsService is the API client for the `/v1/checkouts` endpoint

func (*CheckoutsService) Create

func (service *CheckoutsService) Create(ctx context.Context, storeId int, variantId int, attributes *CheckoutCreateAttributes) (*CheckoutApiResponse, *Response, error)

Create a custom checkout.

https://docs.lemonsqueezy.com/api/checkouts#create-a-checkout

func (*CheckoutsService) Get

func (service *CheckoutsService) Get(ctx context.Context, checkoutID string) (*CheckoutApiResponse, *Response, error)

Get the checkout with the given ID.

https://docs.lemonsqueezy.com/api/checkouts#retrieve-a-checkout

func (*CheckoutsService) List

List returns a paginated list of checkouts.

https://docs.lemonsqueezy.com/api/checkouts#list-all-checkouts

type Client

type Client struct {
	Webhooks             *WebhooksService
	Subscriptions        *SubscriptionsService
	Users                *UsersService
	Stores               *StoresService
	Customers            *CustomersService
	Products             *ProductsService
	Variants             *VariantsService
	Files                *FilesService
	Orders               *OrdersService
	OrderItems           *OrderItemsService
	SubscriptionInvoices *SubscriptionInvoicesService
	SubscriptionItems    *SubscriptionItemsService
	DiscountRedemptions  *DiscountRedemptionsService
	Discounts            *DiscountsService
	Checkouts            *CheckoutsService
	LicenseKeys          *LicenseKeysService
	LicenseKeyInstances  *LicenseKeyInstancesService
	Licenses             *LicensesService
	Prices               *PricesService
	// contains filtered or unexported fields
}

Client is the lemonsqueezy API client. Do not instantiate this client with Client{}. Use the New method instead.

func New

func New(options ...Option) *Client

New creates and returns a new Client from a slice of Option.

type CustomerApiResponse

CustomerApiResponse represents a customer api response

type CustomerAttributes

type CustomerAttributes struct {
	StoreID                       int       `json:"store_id"`
	Name                          string    `json:"name"`
	Email                         string    `json:"email"`
	Status                        string    `json:"status"`
	City                          *string   `json:"city"`
	Region                        *string   `json:"region"`
	Country                       string    `json:"country"`
	TotalRevenueCurrency          int       `json:"total_revenue_currency"`
	Mrr                           int       `json:"mrr"`
	StatusFormatted               string    `json:"status_formatted"`
	CountryFormatted              string    `json:"country_formatted"`
	TotalRevenueCurrencyFormatted string    `json:"total_revenue_currency_formatted"`
	MrrFormatted                  string    `json:"mrr_formatted"`
	CreatedAt                     time.Time `json:"created_at"`
	UpdatedAt                     time.Time `json:"updated_at"`
	TestMode                      bool      `json:"test_mode"`
}

CustomerAttributes are the attributes of a lemonsqueezy customer

type CustomersApiResponse

CustomersApiResponse represents a list of customers api responses.

type CustomersService

type CustomersService service

CustomersService is the API client for the `/v1/customers` endpoint

func (*CustomersService) Get

func (service *CustomersService) Get(ctx context.Context, customerID string) (*CustomerApiResponse, *Response, error)

Get returns the customer with the given ID.

https://docs.lemonsqueezy.com/api/customers#retrieve-a-customer

func (*CustomersService) List

List returns a paginated list of customers.

https://docs.lemonsqueezy.com/api/customers#list-all-customers

type DiscountApiResponse

DiscountApiResponse is the api response for one discount

type DiscountAttributes

type DiscountAttributes struct {
	StoreID              int        `json:"store_id"`
	Name                 string     `json:"name"`
	Code                 string     `json:"code"`
	Amount               int        `json:"amount"`
	AmountType           string     `json:"amount_type"`
	IsLimitedToProducts  bool       `json:"is_limited_to_products"`
	IsLimitedRedemptions bool       `json:"is_limited_redemptions"`
	MaxRedemptions       int        `json:"max_redemptions"`
	StartsAt             *time.Time `json:"starts_at"`
	ExpiresAt            *time.Time `json:"expires_at"`
	Duration             string     `json:"duration"`
	DurationInMonths     int        `json:"duration_in_months"`
	Status               string     `json:"status"`
	StatusFormatted      string     `json:"status_formatted"`
	CreatedAt            time.Time  `json:"created_at"`
	UpdatedAt            time.Time  `json:"updated_at"`
}

DiscountAttributes contains information about a percentage or amount discount that can be applied to an order at checkout via a code.

type DiscountCreateParams

type DiscountCreateParams struct {
	Name       string `json:"name"`
	Code       string `json:"code"`
	Amount     int    `json:"amount"`
	AmountType string `json:"amountType"`
	StoreID    int    `json:"storeID"`
}

DiscountCreateParams are parameters for creating a discount

type DiscountRedemptionApiResponse

DiscountRedemptionApiResponse is the api response for one discount redemption

type DiscountRedemptionAttributes

type DiscountRedemptionAttributes struct {
	DiscountID         int       `json:"discount_id"`
	OrderID            int       `json:"order_id"`
	DiscountName       string    `json:"discount_name"`
	DiscountCode       string    `json:"discount_code"`
	DiscountAmount     int       `json:"discount_amount"`
	DiscountAmountType string    `json:"discount_amount_type"`
	Amount             int       `json:"amount"`
	CreatedAt          time.Time `json:"created_at"`
	UpdatedAt          time.Time `json:"updated_at"`
}

DiscountRedemptionAttributes is a record of a discount being applied to an order.

type DiscountRedemptionsApiResponse

DiscountRedemptionsApiResponse is the api response for a list of discount redemptions.

type DiscountRedemptionsService

type DiscountRedemptionsService service

DiscountRedemptionsService is the API client for the `/v1/discount-redemptions` endpoint

func (*DiscountRedemptionsService) Get

Get returns the discount redemption with the given ID.

https://docs.lemonsqueezy.com/api/discount-redemptions#retrieve-a-discount-redemption

func (*DiscountRedemptionsService) List

List a paginated list of discount redemptions.

https://docs.lemonsqueezy.com/api/discount-redemptions#list-all-discount-redemptions

type DiscountsApiResponse

DiscountsApiResponse is the api response for a list of discounts.

type DiscountsService

type DiscountsService service

DiscountsService is the API client for the `/v1/discounts` endpoint

func (*DiscountsService) Delete

func (service *DiscountsService) Delete(ctx context.Context, discountID string) (*Response, error)

Delete a discount with the given ID.

https://docs.lemonsqueezy.com/api/discounts#delete-a-discount

func (*DiscountsService) Get

func (service *DiscountsService) Get(ctx context.Context, discountID string) (*DiscountApiResponse, *Response, error)

Get the discount with the given ID.

https://docs.lemonsqueezy.com/api/discounts#retrieve-a-discount

func (*DiscountsService) List

List returns a paginated list of discounts.

https://docs.lemonsqueezy.com/api/discounts#list-all-discounts

type FileApiResponse

FileApiResponse is the api response for one file

type FileAttributes

type FileAttributes struct {
	VariantID     int       `json:"variant_id"`
	Identifier    string    `json:"identifier"`
	Name          string    `json:"name"`
	Extension     string    `json:"extension"`
	DownloadURL   string    `json:"download_url"`
	Size          int       `json:"size"`
	SizeFormatted string    `json:"size_formatted"`
	Version       string    `json:"version"`
	Sort          int       `json:"sort"`
	Status        string    `json:"status"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

FileAttributes represents a digital good that can be downloaded by a customer after the product has been purchased.

type FilesApiResponse

FilesApiResponse is the api response for a list of files.

type FilesService

type FilesService service

FilesService is the API client for the `/v1/files` endpoint

func (*FilesService) Get

func (service *FilesService) Get(ctx context.Context, fileID string) (*FileApiResponse, *Response, error)

Get returns the file with the given ID.

https://docs.lemonsqueezy.com/api/files#retrieve-a-file

func (*FilesService) List

func (service *FilesService) List(ctx context.Context) (*FilesApiResponse, *Response, error)

List returns a paginated list of files.

https://docs.lemonsqueezy.com/api/files#list-all-files

type LicenseActivateApiResponse

type LicenseActivateApiResponse struct {
	Activated bool `json:"activated"`
	LicenseAttributes
}

type LicenseAttributes

type LicenseAttributes struct {
	Error      string          `json:"error"`
	LicenseKey LicenseKey      `json:"license_key"`
	Instance   LicenseInstance `json:"instance"`
	Meta       LicenseMeta     `json:"meta"`
}

type LicenseDeactivateApiResponse

type LicenseDeactivateApiResponse struct {
	Deactivated bool `json:"deactivated"`
	LicenseAttributes
}

type LicenseInstance

type LicenseInstance struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

type LicenseKey

type LicenseKey struct {
	ID              int        `json:"id"`
	Status          string     `json:"status"`
	Key             string     `json:"key"`
	ActivationLimit int        `json:"activation_limit"`
	ActivationUsage int        `json:"activation_usage"`
	CreatedAt       time.Time  `json:"created_at"`
	ExpiresAt       *time.Time `json:"expires_at"`
	TestMode        bool       `json:"test_mode"`
}

type LicenseKeyApiResponse

LicenseKeyApiResponse is the api response for one subscription invoice

type LicenseKeyAttributes

type LicenseKeyAttributes struct {
	StoreID         int         `json:"store_id"`
	CustomerID      int         `json:"customer_id"`
	OrderID         int         `json:"order_id"`
	OrderItemID     int         `json:"order_item_id"`
	ProductID       int         `json:"product_id"`
	UserName        string      `json:"user_name"`
	UserEmail       string      `json:"user_email"`
	Key             string      `json:"key"`
	KeyShort        string      `json:"key_short"`
	ActivationLimit int         `json:"activation_limit"`
	InstancesCount  int         `json:"instances_count"`
	Disabled        bool        `json:"disabled"`
	Status          string      `json:"status"`
	StatusFormatted string      `json:"status_formatted"`
	ExpiresAt       interface{} `json:"expires_at"`
	CreatedAt       time.Time   `json:"created_at"`
	UpdatedAt       time.Time   `json:"updated_at"`
}

LicenseKeyAttributes contains information about a license key which can be used to externally verify that customer has access to a product.

type LicenseKeyInstanceApiResponse

LicenseKeyInstanceApiResponse is the api response for one subscription invoice

type LicenseKeyInstanceAttributes

type LicenseKeyInstanceAttributes struct {
	LicenseKeyID int       `json:"license_key_id"`
	Identifier   string    `json:"identifier"`
	Name         string    `json:"name"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

LicenseKeyInstanceAttributes represents a single instance (or activation) of a license key that has been issued to a customer.

type LicenseKeyInstancesApiResponse

LicenseKeyInstancesApiResponse is the api response for a list of subscription invoices.

type LicenseKeyInstancesService

type LicenseKeyInstancesService service

LicenseKeyInstancesService is the API client for the `/v1/license-key-instances` endpoint

func (*LicenseKeyInstancesService) Get

Get retrieves the license key instance with the given ID.

https://docs.lemonsqueezy.com/api/license-key-instances#retrieve-a-license-key-instance

func (*LicenseKeyInstancesService) List

List a paginated list of license key instances.

https://docs.lemonsqueezy.com/api/license-key-instances#list-all-license-key-instances

type LicenseKeysApiResponse

LicenseKeysApiResponse is the api response for a list of subscription invoices.

type LicenseKeysService

type LicenseKeysService service

LicenseKeysService is the API client for the `/v1/license-keys` endpoint

func (*LicenseKeysService) Get

func (service *LicenseKeysService) Get(ctx context.Context, licenseKeyID string) (*LicenseKeyApiResponse, *Response, error)

Get retrieves the license key with the given ID.

https://docs.lemonsqueezy.com/api/license-keys#retrieve-a-license-key

func (*LicenseKeysService) List

List a paginated list of discount redemptions.

https://docs.lemonsqueezy.com/api/license-keys#list-all-license-keys

type LicenseMeta

type LicenseMeta struct {
	StoreID       int    `json:"store_id"`
	OrderID       int    `json:"order_id"`
	OrderItemID   int    `json:"order_item_id"`
	VariantID     int    `json:"variant_id"`
	VariantName   string `json:"variant_name"`
	ProductID     int    `json:"product_id"`
	ProductName   string `json:"product_name"`
	CustomerID    int    `json:"customer_id"`
	CustomerName  string `json:"customer_name"`
	CustomerEmail string `json:"customer_email"`
}

type LicenseValidateApiResponse

type LicenseValidateApiResponse struct {
	Valid bool `json:"valid"`
	LicenseAttributes
}

type LicensesService

type LicensesService service

LicensesService is the API client for the `/v1/licenses` endpoint

func (*LicensesService) Activate

func (service *LicensesService) Activate(ctx context.Context, licenseKey, instanceName string) (*LicenseActivateApiResponse, *Response, error)

Activate a license key.

https://docs.lemonsqueezy.com/help/licensing/license-api

func (*LicensesService) Deactivate

func (service *LicensesService) Deactivate(ctx context.Context, licenseKey, instanceID string) (*LicenseDeactivateApiResponse, *Response, error)

Deactivate a license key.

https://docs.lemonsqueezy.com/help/licensing/license-api

func (*LicensesService) Validate

func (service *LicensesService) Validate(ctx context.Context, licenseKey, instanceID string) (*LicenseValidateApiResponse, *Response, error)

Validate a license key.

https://docs.lemonsqueezy.com/help/licensing/license-api

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is options for constructing a client

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the lemonsqueezy API used to authenticate requests. https://docs.lemonsqueezy.com/api#authentication

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL set's the base url for the flutterwave API

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the underlying HTTP client used for API requests. By default, http.DefaultClient is used.

func WithSigningSecret

func WithSigningSecret(signingSecret string) Option

WithSigningSecret sets the lemonsqueezy webhook signing secret used to authenticate webhook requests. https://docs.lemonsqueezy.com/api/webhooks#webhook-requests

type OrderApiResponse

OrderApiResponse is the api response for one order

type OrderAttributes

type OrderAttributes struct {
	StoreID                int        `json:"store_id"`
	CustomerID             int        `json:"customer_id"`
	Identifier             string     `json:"identifier"`
	OrderNumber            int        `json:"order_number"`
	UserName               string     `json:"user_name"`
	UserEmail              string     `json:"user_email"`
	Currency               string     `json:"currency"`
	CurrencyRate           string     `json:"currency_rate"`
	Subtotal               int        `json:"subtotal"`
	DiscountTotal          int        `json:"discount_total"`
	Tax                    int        `json:"tax"`
	Total                  int        `json:"total"`
	SubtotalUsd            int        `json:"subtotal_usd"`
	DiscountTotalUsd       int        `json:"discount_total_usd"`
	TaxUsd                 int        `json:"tax_usd"`
	TotalUsd               int        `json:"total_usd"`
	TaxName                string     `json:"tax_name"`
	TaxRate                string     `json:"tax_rate"`
	Status                 string     `json:"status"`
	StatusFormatted        string     `json:"status_formatted"`
	Refunded               bool       `json:"refunded"`
	RefundedAt             *time.Time `json:"refunded_at"`
	SubtotalFormatted      string     `json:"subtotal_formatted"`
	DiscountTotalFormatted string     `json:"discount_total_formatted"`
	TaxFormatted           string     `json:"tax_formatted"`
	TotalFormatted         string     `json:"total_formatted"`
	Urls                   struct {
		Receipt string `json:"receipt"`
	} `json:"urls"`
	FirstOrderItem struct {
		ID          int       `json:"id"`
		OrderID     int       `json:"order_id"`
		ProductID   int       `json:"product_id"`
		VariantID   int       `json:"variant_id"`
		ProductName string    `json:"product_name"`
		VariantName string    `json:"variant_name"`
		Price       int       `json:"price"`
		CreatedAt   time.Time `json:"created_at"`
		UpdatedAt   time.Time `json:"updated_at"`
		TestMode    bool      `json:"test_mode"`
	} `json:"first_order_item"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

OrderAttributes for an order which is created when a customer purchases a product.

type OrderItemApiResponse

OrderItemApiResponse is the api response for one order item

type OrderItemAttributes

type OrderItemAttributes struct {
	OrderID     int       `json:"order_id"`
	ProductID   int       `json:"product_id"`
	VariantID   int       `json:"variant_id"`
	ProductName string    `json:"product_name"`
	VariantName string    `json:"variant_name"`
	Price       int       `json:"price"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

OrderItemAttributes is a line item for an order that includes product, variant and price information.

type OrderItemsApiResponse

OrderItemsApiResponse is the api response for a list of order items.

type OrderItemsService

type OrderItemsService service

OrderItemsService is the API client for the `/v1/order-items` endpoint

func (*OrderItemsService) Get

func (service *OrderItemsService) Get(ctx context.Context, orderItemID string) (*OrderItemApiResponse, *Response, error)

Get returns the order-item with the given ID.

https://docs.lemonsqueezy.com/api/order-items#retrieve-an-order-item

func (*OrderItemsService) List

List returns a paginated list of order-items.

https://docs.lemonsqueezy.com/api/order-items#list-all-order-items

type OrdersApiResponse

OrdersApiResponse is the api response for a list of orders.

type OrdersService

type OrdersService service

OrdersService is the API client for the `/v1/orders` endpoint

func (*OrdersService) Get

func (service *OrdersService) Get(ctx context.Context, orderID string) (*OrderApiResponse, *Response, error)

Get returns the order with the given ID.

https://docs.lemonsqueezy.com/api/orders#retrieve-an-order

func (*OrdersService) List

func (service *OrdersService) List(ctx context.Context) (*OrdersApiResponse, *Response, error)

List returns a paginated list of orders.

https://docs.lemonsqueezy.com/api/orders#list-all-orders

type PriceAPIResponse

PriceAPIResponse is the api response for one variant

type PriceAttributes

type PriceAttributes struct {
	VariantID               int                    `json:"variant_id"`
	Category                string                 `json:"category"`
	Scheme                  string                 `json:"scheme"`
	UsageAggregation        any                    `json:"usage_aggregation"`
	UnitPrice               int                    `json:"unit_price"`
	UnitPriceDecimal        any                    `json:"unit_price_decimal"`
	SetupFeeEnabled         bool                   `json:"setup_fee_enabled"`
	SetupFee                any                    `json:"setup_fee"`
	PackageSize             int                    `json:"package_size"`
	Tiers                   []PriceAttributesTiers `json:"tiers"`
	RenewalIntervalUnit     string                 `json:"renewal_interval_unit"`
	RenewalIntervalQuantity int                    `json:"renewal_interval_quantity"`
	TrialIntervalUnit       string                 `json:"trial_interval_unit"`
	TrialIntervalQuantity   int                    `json:"trial_interval_quantity"`
	MinPrice                any                    `json:"min_price"`
	SuggestedPrice          any                    `json:"suggested_price"`
	TaxCode                 string                 `json:"tax_code"`
	CreatedAt               time.Time              `json:"created_at"`
	UpdatedAt               time.Time              `json:"updated_at"`
}

PriceAttributes represents a price added to a variant.

type PriceAttributesTiers

type PriceAttributesTiers struct {
	LastUnit         int `json:"last_unit"`
	UnitPrice        int `json:"unit_price"`
	UnitPriceDecimal any `json:"unit_price_decimal"`
	FixedFee         int `json:"fixed_fee"`
}

PriceAttributesTiers is list of pricing tier objects when using volume and graduated pricing.

type PricesAPIResponse

PricesAPIResponse is the api response for a list of variants.

type PricesService

type PricesService service

PricesService is the API client for the `/v1/prices` endpoint

func (*PricesService) Get

func (service *PricesService) Get(ctx context.Context, priceID int) (*PriceAPIResponse, *Response, error)

Get returns the price with the given ID.

https://docs.lemonsqueezy.com/api/prices#retrieve-a-price

func (*PricesService) List

func (service *PricesService) List(ctx context.Context) (*PricesAPIResponse, *Response, error)

List returns a paginated list of prices.

https://docs.lemonsqueezy.com/api/prices#list-all-prices

type ProductApiResponse

ProductApiResponse represents a product api response

type ProductAttributes

type ProductAttributes struct {
	StoreID         int       `json:"store_id"`
	Name            string    `json:"name"`
	Slug            string    `json:"slug"`
	Description     string    `json:"description"`
	Status          string    `json:"status"`
	StatusFormatted string    `json:"status_formatted"`
	ThumbURL        string    `json:"thumb_url"`
	LargeThumbURL   string    `json:"large_thumb_url"`
	Price           int       `json:"price"`
	PayWhatYouWant  bool      `json:"pay_what_you_want"`
	FromPrice       *int      `json:"from_price"`
	ToPrice         *int      `json:"to_price"`
	BuyNowURL       string    `json:"buy_now_url"`
	PriceFormatted  string    `json:"price_formatted"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

ProductAttributes are the attributes of a lemonsqueezy product

type ProductsApiResponse

ProductsApiResponse represents a list of products api responses.

type ProductsService

type ProductsService service

ProductsService is the API client for the `/v1/products` endpoint

func (*ProductsService) Get

func (service *ProductsService) Get(ctx context.Context, productID string) (*ProductApiResponse, *Response, error)

Get returns the product with the given ID.

https://docs.lemonsqueezy.com/api/products#retrieve-a-product

func (*ProductsService) List

List returns a paginated list of products.

https://docs.lemonsqueezy.com/api/products#list-all-products

type Resource

type Resource[T any] struct {
	Type       string `json:"type"`
	ID         string `json:"id"`
	Attributes T      `json:"attributes"`
}

Resource returns a lemonsqueezy resource. It's similar to ApiResponseData but without the links

type Response

type Response struct {
	HTTPResponse *http.Response
	Body         *[]byte
}

Response captures the http response

func (*Response) Error

func (r *Response) Error() error

Error ensures that the response can be decoded into a string inc ase it's an error response

type StoreApiResponse

StoreApiResponse represents a store api response

type StoreAttributes

type StoreAttributes struct {
	Name             string    `json:"name"`
	Slug             string    `json:"slug"`
	Domain           string    `json:"domain"`
	Url              string    `json:"url"`
	AvatarUrl        string    `json:"avatar_url"`
	Plan             string    `json:"plan"`
	Country          string    `json:"country"`
	CountryNiceName  string    `json:"country_nicename"`
	Currency         string    `json:"currency"`
	TotalSales       int       `json:"total_sales"`
	TotalRevenue     int       `json:"total_revenue"`
	ThirtyDaySales   int       `json:"thirty_day_sales"`
	ThirtyDayRevenue int       `json:"thirty_day_revenue"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
}

StoreAttributes Everything in Lemon Squeezy belongs to a store.

type StoresApiResponse

StoresApiResponse represents a list of store api responses.

type StoresService

type StoresService service

StoresService is the API client for the `/v1/stores` endpoint

func (*StoresService) Get

func (service *StoresService) Get(ctx context.Context, storeID int) (*StoreApiResponse, *Response, error)

Get returns the store with the given ID.

https://docs.lemonsqueezy.com/api/stores#retrieve-a-store

func (*StoresService) List

func (service *StoresService) List(ctx context.Context) (*StoresApiResponse, *Response, error)

List returns a paginated list of stores.

https://docs.lemonsqueezy.com/api/stores#list-all-stores

type Subscription

type Subscription struct {
	StoreID               int                                `json:"store_id"`
	CustomerID            int                                `json:"customer_id"`
	OrderID               int                                `json:"order_id"`
	OrderItemID           int                                `json:"order_item_id"`
	ProductID             int                                `json:"product_id"`
	VariantID             int                                `json:"variant_id"`
	ProductName           string                             `json:"product_name"`
	VariantName           string                             `json:"variant_name"`
	UserName              string                             `json:"user_name"`
	UserEmail             string                             `json:"user_email"`
	Status                string                             `json:"status"`
	StatusFormatted       string                             `json:"status_formatted"`
	CardBrand             string                             `json:"card_brand"`
	CardLastFour          string                             `json:"card_last_four"`
	Pause                 *SubscriptionPause                 `json:"pause"`
	Cancelled             bool                               `json:"cancelled"`
	TrialEndsAt           *time.Time                         `json:"trial_ends_at"`
	BillingAnchor         int                                `json:"billing_anchor"`
	FirstSubscriptionItem *SubscriptionFirstSubscriptionItem `json:"first_subscription_item"`
	Urls                  SubscriptionURLs                   `json:"urls"`
	RenewsAt              time.Time                          `json:"renews_at"`
	EndsAt                *time.Time                         `json:"ends_at"`
	CreatedAt             time.Time                          `json:"created_at"`
	UpdatedAt             time.Time                          `json:"updated_at"`
	TestMode              bool                               `json:"test_mode"`
}

Subscription is created when a subscription product is purchased and will bill the customer on a recurring basis. https://docs.lemonsqueezy.com/api/subscriptions#the-subscription-object

type SubscriptionApiResponse

SubscriptionApiResponse represents a subscription api response

type SubscriptionFirstSubscriptionItem

type SubscriptionFirstSubscriptionItem struct {
	ID int `json:"id"`
	SubscriptionItem
}

SubscriptionSubscriptionItem is an object representing the first subscription item belonging to this subscription.

type SubscriptionInvoiceApiResponse

SubscriptionInvoiceApiResponse is the api response for one subscription invoice

type SubscriptionInvoiceAttributes

type SubscriptionInvoiceAttributes struct {
	StoreID                int        `json:"store_id"`
	SubscriptionID         int        `json:"subscription_id"`
	BillingReason          string     `json:"billing_reason"`
	CardBrand              string     `json:"card_brand"`
	CardLastFour           string     `json:"card_last_four"`
	Currency               string     `json:"currency"`
	CurrencyRate           string     `json:"currency_rate"`
	Subtotal               int        `json:"subtotal"`
	DiscountTotal          int        `json:"discount_total"`
	Tax                    int        `json:"tax"`
	Total                  int        `json:"total"`
	SubtotalUsd            int        `json:"subtotal_usd"`
	DiscountTotalUsd       int        `json:"discount_total_usd"`
	TaxUsd                 int        `json:"tax_usd"`
	TotalUsd               int        `json:"total_usd"`
	Status                 string     `json:"status"`
	StatusFormatted        string     `json:"status_formatted"`
	Refunded               bool       `json:"refunded"`
	RefundedAt             *time.Time `json:"refunded_at"`
	SubtotalFormatted      string     `json:"subtotal_formatted"`
	DiscountTotalFormatted string     `json:"discount_total_formatted"`
	TaxFormatted           string     `json:"tax_formatted"`
	TotalFormatted         string     `json:"total_formatted"`
	Urls                   struct {
		InvoiceURL string `json:"invoice_url"`
	} `json:"urls"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	TestMode  bool      `json:"test_mode"`
}

SubscriptionInvoiceAttributes is the invoice for a subscription https://docs.lemonsqueezy.com/api/subscription-invoices#the-subscription-invoice-object

type SubscriptionInvoicesApiResponse

SubscriptionInvoicesApiResponse is the api response for a list of subscription invoices.

type SubscriptionInvoicesService

type SubscriptionInvoicesService service

SubscriptionInvoicesService is the API client for the `/v1/subscription-invoices` endpoint

func (*SubscriptionInvoicesService) Get

Get returns the subscription invoice with the given ID.

https://docs.lemonsqueezy.com/api/subscription-invoices#retrieve-a-subscription-invoice

func (*SubscriptionInvoicesService) List

List a paginated list of subscription invoices.

https://docs.lemonsqueezy.com/api/subscription-invoices#list-all-subscription-invoices

type SubscriptionItem

type SubscriptionItem struct {
	SubscriptionID int       `json:"subscription_id"`
	PriceID        int       `json:"price_id"`
	Quantity       int       `json:"quantity"`
	IsUsageBased   bool      `json:"is_usage_based"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

In Lemon Squeezy A subscription item is an object that links a price to a subscription and also contains quantity information. https://docs.lemonsqueezy.com/api/subscription-items#the-subscription-item-object

type SubscriptionItemApiResponse

SubscriptionItemApiResponse represents a subscription item api response

type SubscriptionItemCurrentUsageApiResponse

type SubscriptionItemCurrentUsageApiResponse struct {
	Jsonapi ApiResponseJSONAPI                          `json:"jsonapi"`
	Meta    ApiResponseMetaSubscriptionItemCurrentUsage `json:"meta"`
}

SubscriptionItemsCurrentUsageApiResponse represents the subscription item's current usage api response

type SubscriptionItemListParams

type SubscriptionItemListParams struct {
	SubscriptionID string
	PriceID        string
}

SubscriptionItemListParams are parameters for filtering list responses

type SubscriptionItemUpdateParams

type SubscriptionItemUpdateParams struct {
	ID         string                                 `json:"id"`
	Attributes SubscriptionItemUpdateParamsAttributes `json:"attributes"`
}

SubscriptionUpdateParams are parameters for updating a subscription

type SubscriptionItemUpdateParamsAttributes

type SubscriptionItemUpdateParamsAttributes struct {
	Quantity int `json:"quantity,omitempty"`
}

SubscriptionUpdateParamsAttributes are subscription update attributes

type SubscriptionItemsApiResponse

SubscriptionItemsApiResponse represents a list of subscription items api responses

type SubscriptionItemsService

type SubscriptionItemsService service

SubscriptionItemsService is the API client for the `/subscription-items` endpoint

func (*SubscriptionItemsService) CurrentUsage

func (service *SubscriptionItemsService) CurrentUsage(ctx context.Context, subscriptionItemID string) (*SubscriptionItemCurrentUsageApiResponse, *Response, error)

Current usage returns a subscription item's current usage with the given ID.

https://docs.lemonsqueezy.com/api/subscription-items#retrieve-a-subscription-item-s-current-usage

func (*SubscriptionItemsService) Get

func (service *SubscriptionItemsService) Get(ctx context.Context, subscriptionItemID string) (*SubscriptionItemApiResponse, *Response, error)

Get returns the subscription item with the given ID.

https://docs.lemonsqueezy.com/api/subscription-items#retrieve-a-subscription-item

func (*SubscriptionItemsService) List

List returns a paginated list of subscription items you can add extra query params to your request

https://docs.lemonsqueezy.com/api/subscriptions#list-all-subscriptions

type SubscriptionPause

type SubscriptionPause struct {
	Mode      string    `json:"mode"`
	ResumesAt time.Time `json:"resumes_at"`
}

SubscriptionPause is object of customer-facing URLs for managing the subscription.

type SubscriptionURLs

type SubscriptionURLs struct {
	UpdatePaymentMethod string `json:"update_payment_method"`
	CustomerPortal      string `json:"customer_portal"`
}

SubscriptionURLs is object of customer-facing URLs for managing the subscription.

type SubscriptionUpdateParams

type SubscriptionUpdateParams struct {
	ID         string                             `json:"id"`
	Attributes SubscriptionUpdateParamsAttributes `json:"attributes"`
}

SubscriptionUpdateParams are parameters for updating a subscription

type SubscriptionUpdateParamsAttributes

type SubscriptionUpdateParamsAttributes struct {
	ProductID          int                `json:"product_id,omitempty"`
	VariantID          int                `json:"variant_id,omitempty"`
	BillingAnchor      int                `json:"billing_anchor,omitempty"`
	Cancelled          bool               `json:"cancelled"`
	Pause              *SubscriptionPause `json:"pause,omitempty"`
	InvoiceImmediately bool               `json:"invoice_immediately"`
	DisableProrations  bool               `json:"disable_prorations"`
}

SubscriptionUpdateParamsAttributes are subscription update attributes

type SubscriptionsApiResponse

SubscriptionsApiResponse represents a list of subscription api responses.

type SubscriptionsService

type SubscriptionsService service

SubscriptionsService is the API client for the `/subscriptions` endpoint

func (*SubscriptionsService) Cancel

func (service *SubscriptionsService) Cancel(ctx context.Context, subscriptionID string) (*SubscriptionApiResponse, *Response, error)

Cancel an active subscription the given ID.

https://docs.lemonsqueezy.com/api/subscriptions#retrieve-a-subscription

func (*SubscriptionsService) Get

func (service *SubscriptionsService) Get(ctx context.Context, subscriptionID string) (*SubscriptionApiResponse, *Response, error)

Get returns the subscription with the given ID.

https://docs.lemonsqueezy.com/api/subscriptions#retrieve-a-subscription

func (*SubscriptionsService) List

List returns a paginated list of subscriptions ordered by created_at (descending)

https://docs.lemonsqueezy.com/api/subscriptions#list-all-subscriptions

func (*SubscriptionsService) Update

Update an existing subscription to specific parameter

https://docs.lemonsqueezy.com/api/subscriptions#update-a-subscription

type UserApiResponse

UserApiResponse represents a UserAttributes api response

type UserAttributes

type UserAttributes struct {
	Name            string    `json:"name"`
	Email           string    `json:"email"`
	Color           string    `json:"color"`
	AvatarURL       string    `json:"avatar_url"`
	HasCustomAvatar bool      `json:"has_custom_avatar"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
}

UserAttributes represents your personal user account that you use to log in to Lemon Squeezy.

type UsersService

type UsersService service

UsersService is the API client for the `/v1/users` endpoint

func (*UsersService) Me

func (service *UsersService) Me(ctx context.Context) (*UserApiResponse, *Response, error)

Me retrieves the currently authenticated user. https://docs.lemonsqueezy.com/api/users#retrieve-the-authenticated-user

type VariantAPIResponse

VariantAPIResponse is the api response for one variant

type VariantAttributes

type VariantAttributes struct {
	ProductID                int       `json:"product_id"`
	Name                     string    `json:"name"`
	Slug                     string    `json:"slug"`
	Description              string    `json:"description"`
	Price                    int       `json:"price"`
	IsSubscription           bool      `json:"is_subscription"`
	Interval                 *string   `json:"interval"`
	IntervalCount            *int      `json:"interval_count"`
	HasFreeTrial             bool      `json:"has_free_trial"`
	TrialInterval            string    `json:"trial_interval"`
	TrialIntervalCount       int       `json:"trial_interval_count"`
	PayWhatYouWant           bool      `json:"pay_what_you_want"`
	MinPrice                 int       `json:"min_price"`
	SuggestedPrice           int       `json:"suggested_price"`
	HasLicenseKeys           bool      `json:"has_license_keys"`
	LicenseActivationLimit   int       `json:"license_activation_limit"`
	IsLicenseLimitUnlimited  bool      `json:"is_license_limit_unlimited"`
	LicenseLengthValue       int       `json:"license_length_value"`
	LicenseLengthUnit        string    `json:"license_length_unit"`
	IsLicenseLengthUnlimited bool      `json:"is_license_length_unlimited"`
	Sort                     int       `json:"sort"`
	Status                   string    `json:"status"`
	StatusFormatted          string    `json:"status_formatted"`
	TestMode                 bool      `json:"test_mode"`
	CreatedAt                time.Time `json:"created_at"`
	UpdatedAt                time.Time `json:"updated_at"`
}

VariantAttributes represents a different option that is presented to the customer at checkout.

type VariantsAPIResponse

VariantsAPIResponse is the api response for a list of variants.

type VariantsService

type VariantsService service

VariantsService is the API client for the `/v1/variants` endpoint

func (*VariantsService) Get

func (service *VariantsService) Get(ctx context.Context, variantID int) (*VariantAPIResponse, *Response, error)

Get returns the variant with the given ID.

https://docs.lemonsqueezy.com/api/variants#retrieve-a-variant

func (*VariantsService) List

List returns a paginated list of variants.

https://docs.lemonsqueezy.com/api/variants#list-all-variants

type WebhookApiResponse

WebhookApiResponse is the api response for one webhook

type WebhookAttributes

type WebhookAttributes struct {
	StoreID    int        `json:"store_id"`
	URL        string     `json:"url"`
	Events     []string   `json:"events"`
	LastSentAt *time.Time `json:"last_sent_at"`
	CreatedAt  time.Time  `json:"created_at"`
	UpdatedAt  time.Time  `json:"updated_at"`
	TestMode   bool       `json:"test_mode"`
}

WebhookAttributes contains information about a webhook.

type WebhookCreateParams

type WebhookCreateParams struct {
	URL    string   `json:"url"`
	Events []string `json:"events"`
	Secret string   `json:"secret"`
}

WebhookCreateParams are parameters for creating a webhook

type WebhookRequest

type WebhookRequest[T, R any] struct {
	Meta WebhookRequestMeta       `json:"meta"`
	Data WebhookRequestData[T, R] `json:"data"`
}

WebhookRequest represents a webhook request

type WebhookRequestData

type WebhookRequestData[Attributes, Relationships any] struct {
	Type          string              `json:"type"`
	ID            string              `json:"id"`
	Attributes    Attributes          `json:"attributes"`
	Relationships Relationships       `json:"relationships"`
	Links         ApiResponseSelfLink `json:"links"`
}

WebhookRequestData webhook request data

type WebhookRequestLicenseKey

WebhookRequestLicenseKey is the payload for license key related events e.g. license_key_created

type WebhookRequestMeta

type WebhookRequestMeta struct {
	EventName  string         `json:"event_name"`
	TestMode   bool           `json:"test_mode"`
	CustomData map[string]any `json:"custom_data"`
}

WebhookRequestMeta contains meta data about the request

type WebhookRequestOrder

WebhookRequestOrder is the payload for order related events e.g. order_created, order_refunded

type WebhookRequestSubscription

WebhookRequestSubscription is the payload for subscription related events e.g. subscription_created, subscription_updated

type WebhookRequestSubscriptionInvoice

WebhookRequestSubscriptionInvoice is the payload for subscription invoice related events e.g. subscription_payment_success, subscription_payment_failed

type WebhookUpdateParams

type WebhookUpdateParams struct {
	ID     string   `json:"id"`
	Secret string   `json:"secret"`
	Events []string `json:"events"`
}

WebhookUpdateParams are parameters for updating a webhook

type WebhooksApiResponse

WebhooksApiResponse is the api response for a list of webhooks.

type WebhooksService

type WebhooksService service

WebhooksService is the used to verify the signature in webhook requests

func (*WebhooksService) Create

func (service *WebhooksService) Create(ctx context.Context, storeId int, params *WebhookCreateParams) (*WebhookApiResponse, *Response, error)

Create a webhook.

https://docs.lemonsqueezy.com/api/webhooks#create-a-webhook

func (*WebhooksService) Delete

func (service *WebhooksService) Delete(ctx context.Context, webhookID string) (*Response, error)

Delete a webhook with the given ID.

https://docs.lemonsqueezy.com/api/webhooks#delete-a-webhook

func (*WebhooksService) Get

func (service *WebhooksService) Get(ctx context.Context, webhookID string) (*WebhookApiResponse, *Response, error)

Get the webhook with the given ID.

https://docs.lemonsqueezy.com/api/webhooks#retrieve-a-webhook

func (*WebhooksService) List

List returns a paginated list of webhooks.

https://docs.lemonsqueezy.com/api/webhooks#list-all-webhooks

func (*WebhooksService) Update

Update an existing webhook

https://docs.lemonsqueezy.com/api/subscriptions#update-a-webhook

func (*WebhooksService) Verify

func (service *WebhooksService) Verify(_ context.Context, signature string, body []byte) bool

Verify the signature in webhook requests

https://docs.lemonsqueezy.com/api/webhooks#signing-requests

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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