lemonsqueezy

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 13 Imported by: 1

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/NdoleStudio/lemonsqueezy-go

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

import "github.com/NdoleStudio/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/NdoleStudio/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 APIResponseRelationshipsCheckout added in v1.2.2

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

APIResponseRelationshipsCheckout relationships of a checkout

type APIResponseRelationshipsDiscount added in v1.2.2

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

APIResponseRelationshipsDiscount relationships of a discount

type APIResponseRelationshipsOrder added in v1.2.0

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 APIResponseRelationshipsPrice added in v1.2.0

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

APIResponseRelationshipsPrice relationships of a variant

type APIResponseRelationshipsVariant added in v1.2.0

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 added in v0.0.4

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 added in v0.0.3

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 added in v0.0.3

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

ApiResponseListMeta defines the meta data for a list api response

type ApiResponseListMetaPage added in v0.0.3

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 added in v1.0.4

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 added in v0.0.12

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

ApiResponseRelationshipWebhook relationships of a webhook

type ApiResponseRelationshipsCustomer added in v0.0.5

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 ApiResponseRelationshipsDiscountRedemption added in v0.0.8

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

ApiResponseRelationshipsDiscountRedemption relationships of a discount redemption

type ApiResponseRelationshipsFile added in v0.0.6

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

ApiResponseRelationshipsFile relationships of a file

type ApiResponseRelationshipsLicenseKey added in v0.0.11

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 added in v0.0.11

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

ApiResponseRelationshipsLicenseKeyInstance relationships of a license key

type ApiResponseRelationshipsOrderItem added in v0.0.7

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

ApiResponseRelationshipsOrderItem relationships of an order-item

type ApiResponseRelationshipsProduct added in v0.0.5

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

ApiResponseRelationshipsProduct relationships of a product

type ApiResponseRelationshipsStore added in v0.0.4

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 added in v0.0.3

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 added in v0.0.8

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

ApiResponseRelationshipsSubscriptionInvoice relationships of a subscription invoice

type ApiResponseRelationshipsSubscriptionItem added in v1.0.3

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 added in v0.0.4

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 added in v0.0.10

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

BillingAddress contains the checkout billing address

type CheckoutAPIResponse added in v1.2.2

CheckoutAPIResponse is the api response for one checkout

type CheckoutAttributes added in v0.0.10

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 added in v1.1.0

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       *string                      `json:"expires_at,omitempty"`
}

CheckoutCreateAttributes represents individual parameters for creating a checkout.

type CheckoutCreateData added in v1.1.0

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                map[string]any               `json:"custom,omitempty"`
	VariantQuantities     []CheckoutCreateDataQuantity `json:"variant_quantities,omitempty"`
}

CheckoutCreateData represents the data options for creating a checkout.

type CheckoutCreateDataQuantity added in v1.1.0

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

CheckoutCreateDataQuantity represents variant quantities when creating checkout

type CheckoutCreateOptions added in v1.1.0

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 added in v1.1.0

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 added in v0.0.10

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 added in v0.0.10

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 added in v0.0.10

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 added in v0.0.10

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 added in v1.2.2

CheckoutsAPIResponse is the api response for a list of checkout.

type CheckoutsService added in v0.0.10

type CheckoutsService service

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

func (*CheckoutsService) Create added in v0.0.10

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 added in v0.0.10

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 added in v0.0.10

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 added in v0.0.5

CustomerApiResponse represents a customer api response

type CustomerAttributes added in v0.0.5

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"`
	Urls                          struct {
		CustomerPortal string `json:"customer_portal"`
	} `json:"urls"`
	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 added in v0.0.5

CustomersApiResponse represents a list of customers api responses.

type CustomersService added in v0.0.5

type CustomersService service

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

func (*CustomersService) Get added in v0.0.5

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 added in v0.0.5

List returns a paginated list of customers.

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

type DiscountAPIResponse added in v1.2.2

DiscountAPIResponse is the api response for one discount

type DiscountAttributes added in v0.0.9

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 added in v0.0.9

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 added in v0.0.8

DiscountRedemptionApiResponse is the api response for one discount redemption

type DiscountRedemptionAttributes added in v0.0.8

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 added in v0.0.8

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

type DiscountRedemptionsService added in v0.0.8

type DiscountRedemptionsService service

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

func (*DiscountRedemptionsService) Get added in v0.0.8

Get returns the discount redemption with the given ID.

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

func (*DiscountRedemptionsService) List added in v0.0.8

List a paginated list of discount redemptions.

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

type DiscountsAPIResponse added in v1.2.2

DiscountsAPIResponse is the api response for a list of discounts.

type DiscountsService added in v0.0.9

type DiscountsService service

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

func (*DiscountsService) Create added in v0.0.9

Create a discount.

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

func (*DiscountsService) Delete added in v0.0.9

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 added in v0.0.9

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 added in v0.0.9

List returns a paginated list of discounts.

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

type FileApiResponse added in v0.0.6

FileApiResponse is the api response for one file

type FileAttributes added in v0.0.6

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 added in v0.0.6

FilesApiResponse is the api response for a list of files.

type FilesService added in v0.0.6

type FilesService service

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

func (*FilesService) Get added in v0.0.6

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 added in v0.0.6

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 added in v1.0.5

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

type LicenseAttributes added in v1.0.5

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

type LicenseDeactivateApiResponse added in v1.0.5

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

type LicenseInstance added in v1.0.5

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

type LicenseKey added in v1.0.5

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 added in v0.0.11

LicenseKeyApiResponse is the api response for one subscription invoice

type LicenseKeyAttributes added in v0.0.11

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 added in v0.0.11

LicenseKeyInstanceApiResponse is the api response for one subscription invoice

type LicenseKeyInstanceAttributes added in v0.0.11

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 added in v0.0.11

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

type LicenseKeyInstancesService added in v0.0.11

type LicenseKeyInstancesService service

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

func (*LicenseKeyInstancesService) Get added in v0.0.11

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 added in v0.0.11

List a paginated list of license key instances.

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

type LicenseKeysApiResponse added in v0.0.11

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

type LicenseKeysService added in v0.0.11

type LicenseKeysService service

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

func (*LicenseKeysService) Get added in v0.0.11

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 added in v0.0.11

List a paginated list of discount redemptions.

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

type LicenseMeta added in v1.0.5

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 added in v1.0.5

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

type LicensesService added in v1.0.5

type LicensesService service

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

func (*LicensesService) Activate added in v1.0.5

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 added in v1.0.5

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 added in v1.0.5

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 added in v1.2.0

OrderAPIResponse is the api response for one order

type OrderAttributes added in v0.0.7

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                any        `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 added in v0.0.7

OrderItemApiResponse is the api response for one order item

type OrderItemAttributes added in v0.0.7

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 added in v0.0.7

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

type OrderItemsService added in v0.0.7

type OrderItemsService service

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

func (*OrderItemsService) Get added in v0.0.7

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 added in v0.0.7

List returns a paginated list of order-items.

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

type OrdersAPIResponse added in v1.2.0

OrdersAPIResponse is the api response for a list of orders.

type OrdersService added in v0.0.7

type OrdersService service

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

func (*OrdersService) Get added in v0.0.7

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 added in v0.0.7

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 added in v1.2.0

PriceAPIResponse is the api response for one variant

type PriceAttributes added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

PricesAPIResponse is the api response for a list of variants.

type PricesService added in v1.2.0

type PricesService service

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

func (*PricesService) Get added in v1.2.0

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 added in v1.2.0

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 added in v0.0.5

ProductApiResponse represents a product api response

type ProductAttributes added in v0.0.5

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           any       `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 added in v0.0.5

ProductsApiResponse represents a list of products api responses.

type ProductsService added in v0.0.5

type ProductsService service

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

func (*ProductsService) Get added in v0.0.5

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 added in v0.0.5

List returns a paginated list of products.

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

type Resource added in v0.0.3

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 added in v0.0.4

StoreApiResponse represents a store api response

type StoreAttributes added in v0.0.4

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 added in v0.0.5

StoresApiResponse represents a list of store api responses.

type StoresService added in v0.0.4

type StoresService service

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

func (*StoresService) Get added in v0.0.4

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 added in v0.0.4

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 added in v1.0.4

SubscriptionApiResponse represents a subscription api response

type SubscriptionFirstSubscriptionItem added in v1.0.4

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

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

type SubscriptionInvoiceApiResponse added in v0.0.8

SubscriptionInvoiceApiResponse is the api response for one subscription invoice

type SubscriptionInvoiceAttributes added in v0.0.8

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 added in v0.0.8

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

type SubscriptionInvoicesService added in v0.0.8

type SubscriptionInvoicesService service

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

func (*SubscriptionInvoicesService) Get added in v0.0.8

Get returns the subscription invoice with the given ID.

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

func (*SubscriptionInvoicesService) List added in v0.0.8

List a paginated list of subscription invoices.

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

type SubscriptionItem added in v1.0.3

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 added in v1.0.3

SubscriptionItemApiResponse represents a subscription item api response

type SubscriptionItemCurrentUsageApiResponse added in v1.0.4

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

SubscriptionItemsCurrentUsageApiResponse represents the subscription item's current usage api response

type SubscriptionItemListParams added in v1.0.4

type SubscriptionItemListParams struct {
	SubscriptionID string
	PriceID        string
}

SubscriptionItemListParams are parameters for filtering list responses

type SubscriptionItemUpdateParams added in v1.0.3

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

SubscriptionUpdateParams are parameters for updating a subscription

type SubscriptionItemUpdateParamsAttributes added in v1.0.3

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

SubscriptionUpdateParamsAttributes are subscription update attributes

type SubscriptionItemsApiResponse added in v1.0.3

SubscriptionItemsApiResponse represents a list of subscription items api responses

type SubscriptionItemsService added in v1.0.4

type SubscriptionItemsService service

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

func (*SubscriptionItemsService) CurrentUsage added in v1.0.4

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 added in v1.0.4

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 added in v1.0.4

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

func (*SubscriptionItemsService) Update added in v1.0.4

Update a subscription item

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

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 added in v0.0.3

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

SubscriptionUpdateParams are parameters for updating a subscription

type SubscriptionUpdateParamsAttributes added in v0.0.3

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 added in v1.0.4

SubscriptionsApiResponse represents a list of subscription api responses.

type SubscriptionsService added in v0.0.3

type SubscriptionsService service

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

func (*SubscriptionsService) Cancel added in v0.0.3

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 added in v0.0.3

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 added in v0.0.3

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

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

func (*SubscriptionsService) Update added in v0.0.3

Update an existing subscription to specific parameter

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

type UserApiResponse added in v0.0.4

UserApiResponse represents a UserAttributes api response

type UserAttributes added in v0.0.4

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 added in v0.0.4

type UsersService service

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

func (*UsersService) Me added in v0.0.4

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 added in v1.2.0

VariantAPIResponse is the api response for one variant

type VariantAttributes added in v0.0.6

type VariantAttributes struct {
	ProductID                int       `json:"product_id"`
	Name                     string    `json:"name"`
	Slug                     string    `json:"slug"`
	Description              string    `json:"description"`
	Price                    any       `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 added in v1.2.0

VariantsAPIResponse is the api response for a list of variants.

type VariantsService added in v0.0.6

type VariantsService service

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

func (*VariantsService) Get added in v0.0.6

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 added in v0.0.6

List returns a paginated list of variants.

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

type WebhookApiResponse added in v0.0.12

WebhookApiResponse is the api response for one webhook

type WebhookAttributes added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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

type WebhookRequestSubscription added in v0.0.12

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

type WebhookRequestSubscriptionInvoice added in v0.0.12

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

type WebhookUpdateParams added in v0.0.12

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

WebhookUpdateParams are parameters for updating a webhook

type WebhooksApiResponse added in v0.0.12

WebhooksApiResponse is the api response for a list of webhooks.

type WebhooksService added in v0.0.3

type WebhooksService service

WebhooksService is the used to verify the signature in webhook requests

func (*WebhooksService) Create added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

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 added in v0.0.12

List returns a paginated list of webhooks.

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

func (*WebhooksService) Update added in v0.0.12

Update an existing webhook

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

func (*WebhooksService) Verify added in v0.0.3

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