### Discount Starts At Property Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Discount_Attributes An ISO-8601 formatted string representing the date and time when the discount becomes active. Can be null if no start date is set. ```swift public let startsAt: String? ``` -------------------------------- ### List and get files Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function demonstrates how to retrieve a list of files associated with a product variant. Files are downloadable assets. ```APIDOC ## Files ### Description Fetches a list of files associated with a specific product variant. These files are the downloadable assets for the product. ### Method `getFiles(queryItems:)` ### Parameters #### Query Parameters - **filter[variant_id]** (String) - Required - The ID of the product variant to filter files by. ### Request Example ```json { "queryItems": [ { "name": "filter[variant_id]", "value": "" } ] } ``` ### Response Example (Success) ```json { "data": [ { "id": "", "attributes": { "name": "MySoftware.dmg", "size": 10485760, "status": "ready" // ... other attributes } } // ... other files ] } ``` ``` -------------------------------- ### List and Get Files in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieves a list of downloadable files associated with a specific product variant. Requires a variant ID. ```swift func loadFiles(variantId: String) async { do { let filter = URLQueryItem(name: "filter[variant_id]", value: variantId) let response = try await lemon.getFiles(queryItems: [filter]) for file in response.data { let a = file.attributes print("\(file.id): \(a.name) (\(a.size) bytes) — \(a.status)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### getProduct Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single product by ID. ```APIDOC ## getProduct ### Description Get a single product by ID. ### Method GET ### Endpoint `/v1/products/:id` ``` -------------------------------- ### Get Files Method Signature Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getFiles(pageNumber_pageSize_queryItems_) This is the method signature for retrieving a list of files. It supports optional pagination and query parameters. ```swift public func getFiles(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### Get a Single Product Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches details for a specific product by its ID. Includes error handling for the API request. ```swift func loadSingleProduct(productId: String) async { do { let response = try await lemon.getProduct(productId) let p = response.data.attributes print("Product: \(p.name), Price: \(p.priceFormatted ?? "N/A")") } catch { print("Error: \(error)") } } ``` -------------------------------- ### List and Get Subscription Invoices Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Demonstrates how to list all invoices for a given subscription or retrieve a single invoice. Requires a valid subscription ID for filtering. ```swift func loadSubscriptionInvoices(subscriptionId: String) async { do { let filter = URLQueryItem(name: "filter[subscription_id]", value: subscriptionId) let response = try await lemon.getSubscriptionInvoices(queryItems: [filter]) for invoice in response.data { print("\(invoice.id): \(invoice.attributes.status) — \(invoice.attributes.totalFormatted)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### getLicenseKeyInstance Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single license key instance by ID. ```APIDOC ## getLicenseKeyInstance ### Description Get a single license key instance by ID. ### Method GET ### Endpoint `/v1/license-key-instances/:id` ``` -------------------------------- ### Create and List Usage Records Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Provides examples for creating usage records for metered subscriptions and listing existing usage records. Ensure the subscription item ID is correct when creating records. ```swift func trackUsage(subscriptionItemId: Int, quantity: Int) async { let body: [String: Any] = [ "data": [ "type": "usage-records", "attributes": [ "quantity": quantity, "action": "increment" ], "relationships": [ "subscription-item": [ "data": ["type": "subscription-items", "id": String(subscriptionItemId)] ] ] ] ] do { let record = try await lemon.createUsageRecord(body: body) print("Recorded usage: \(record.data.attributes.quantity)") } catch { print("Error: \(error)") } } ``` ```swift func loadUsageRecords() async { do { let response = try await lemon.getUsageRecords(pageNumber: 1, pageSize: 25) for record in response.data { print("\(record.id): qty=\(record.attributes.quantity) at \(record.attributes.createdAt)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### getFile Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single file by ID. ```APIDOC ## getFile ### Description Get a single file by ID. ### Method GET ### Endpoint `/v1/files/:id` ``` -------------------------------- ### Manage Customers: Create, Get, Update, List Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Illustrates the full lifecycle of customer management, including creation, retrieval, updating, and listing customers. Requires a valid store ID for creation. ```swift func manageCustomers() async { do { // Create let createBody: [String: Any] = [ "data": [ "type": "customers", "attributes": [ "name": "Jane Doe", "email": "jane@example.com" ], "relationships": [ "store": ["data": ["type": "stores", "id": "12345"]] ] ] ] let created = try await lemon.createCustomer(body: createBody) let customerId = created.data.id print("Created customer: \(customerId)") // Retrieve let fetched = try await lemon.getCustomer(customerId) print("Name: \(fetched.data.attributes.name)") // Update let updateBody: [String: Any] = [ "data": ["type": "customers", "id": customerId, "attributes": ["name": "Jane Smith"]] ] let updated = try await lemon.updateCustomer(customerId, body: updateBody) print("Updated name: \(updated.data.attributes.name)") // List let list = try await lemon.getCustomers(pageNumber: 1, pageSize: 10) print("Total customers: \(list.meta?.page.total ?? 0)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### List and Get Affiliates Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function demonstrates how to load a list of affiliates using the SDK. It specifies the page number and page size for the request and iterates through the response data to print affiliate information. ```APIDOC ## List and get affiliates ### Description This function demonstrates how to load a list of affiliates using the SDK. It specifies the page number and page size for the request and iterates through the response data to print affiliate information. ### Method `lemon.getAffiliates(pageNumber: Int, pageSize: Int)` ### Parameters #### Query Parameters - **pageNumber** (Int) - Required - The page number to retrieve. - **pageSize** (Int) - Required - The number of items per page. ### Response #### Success Response - **data** (Array) - A list of affiliate objects. - **meta** (Meta.Page) - Pagination information. ### Request Example ```swift func loadAffiliates() async { do { let response = try await lemon.getAffiliates(pageNumber: 1, pageSize: 10) for affiliate in response.data { print("\(affiliate.id): \(affiliate.attributes.email)") } } catch { print("Error: \(error)") } } ``` ``` -------------------------------- ### List and get webhooks Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function demonstrates how to retrieve a list of configured webhooks for a store. Webhooks are used for real-time event notifications. ```APIDOC ## Webhooks ### Description Fetches a list of webhooks configured for a store. Webhooks enable Lemon Squeezy to send event notifications to your specified URLs. ### Method `getWebhooks(queryItems:)` ### Parameters #### Query Parameters - **filter[store_id]** (String) - Required - The ID of the store to filter webhooks by. ### Request Example ```json { "queryItems": [ { "name": "filter[store_id]", "value": "" } ] } ``` ### Response Example (Success) ```json { "data": [ { "id": "", "attributes": { "url": "https://your-app.com/webhooks", "events": ["order_created", "order_updated"] // ... other attributes } } // ... other webhooks ] } ``` ``` -------------------------------- ### Get License Key Instances Method Signature Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeyInstances(pageNumber_pageSize_) This is the method signature for retrieving license key instances. It supports optional page number and page size parameters for pagination. ```swift public func getLicenseKeyInstances(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### List and Get Order Items in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches order items for a given order, displaying product IDs and formatted prices. Requires an order ID. ```swift func loadOrderItems(orderId: String) async { do { let filter = URLQueryItem(name: "filter[order_id]", value: orderId) let response = try await lemon.getOrderItems(queryItems: [filter]) for item in response.data { print("\(item.id): product \(item.attributes.productId) — \(item.attributes.priceFormatted)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### Manage Subscriptions: Get, Pause, Cancel Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Demonstrates how to retrieve subscription details, pause collection, and cancel a subscription using the SDK. Ensure the subscription ID is valid. ```swift func manageSubscription(subscriptionId: String) async { do { // Retrieve let response = try await lemon.getSubscription(subscriptionId) print("Status: \(response.data.attributes.status)") print("Portal URL: \(response.data.attributes.urls.customerPortal)") // Pause collection let pauseBody: [String: Any] = [ "data": [ "type": "subscriptions", "id": subscriptionId, "attributes": [ "pause": ["mode": "void"] ] ] ] let updated = try await lemon.updateSubscription(subscriptionId, body: pauseBody) print("Updated status: \(updated.data.attributes.status)") // Cancel let cancelled = try await lemon.cancelSubscription(subscriptionId) print("Cancelled: \(cancelled.data.attributes.cancelled)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### Get License Key Instances Function Signature Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeyInstances(pageNumber_pageSize_queryItems_) This is the function signature for retrieving license key instances. It includes default values for pagination parameters. ```swift public func getLicenseKeyInstances(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### getCustomer Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single customer by ID. ```APIDOC ## getCustomer ### Description Get a single customer by ID. ### Method GET ### Endpoint `/v1/customers/:id` ``` -------------------------------- ### List discounts / Get a single discount / List redemptions Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function shows how to retrieve a list of discounts within a store and also how to fetch discount redemptions. ```APIDOC ## Discounts ### Description Provides functionality to list available discounts within a store and to retrieve a list of all discount redemptions. ### Method `getDiscounts(pageNumber:pageSize:queryItems:)` and `getDiscountRedemptions(pageNumber:pageSize:)` ### Parameters #### `getDiscounts` Parameters - **pageNumber** (Integer) - Optional - The page number to retrieve. - **pageSize** (Integer) - Optional - The number of items per page. - **queryItems** (Array of URLQueryItem) - Optional - Allows filtering, e.g., `filter[store_id]`. #### `getDiscountRedemptions` Parameters - **pageNumber** (Integer) - Optional - The page number to retrieve. - **pageSize** (Integer) - Optional - The number of items per page. ### Request Example (List Discounts) ```json { "pageNumber": 1, "pageSize": 10, "queryItems": [ { "name": "filter[store_id]", "value": "" } ] } ``` ### Response Example (List Discounts Success) ```json { "data": [ { "id": "", "attributes": { "code": "SUMMERSALE", "amount": 20, "amount_type": "percent", "expires_at": "2024-12-31T00:00:00.000Z" // ... other attributes } } // ... other discounts ], "meta": { // ... pagination info } } ``` ### Request Example (List Redemptions) ```json { "pageNumber": 1, "pageSize": 20 } ``` ### Response Example (List Redemptions Success) ```json { "data": [ { "id": "", "attributes": { // ... redemption attributes } } // ... other redemptions ], "meta": { "page": { "total": 150 // ... other pagination info } } } ``` ``` -------------------------------- ### getStore(_:queryItems:) Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getStore(__queryItems_) Retrieves a single store by its ID. This is equivalent to making a GET request to the /v1/stores/:id endpoint. ```APIDOC ## GET /v1/stores/:id ### Description Retrieves a single store by its ID. ### Method GET ### Endpoint /v1/stores/:id ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the store to retrieve. #### Query Parameters - **queryItems** ([URLQueryItem]) - Optional - An array of `URLQueryItem` to be passed as query parameters. ### Response #### Success Response (200) - **data** (array of Store) - Contains an array of `Store` objects. (Note: The source implies a single store, but mentions an array in the return description. This is preserved as per source.) ``` -------------------------------- ### List and Get Prices Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches a list of prices associated with a variant or a single price by its ID. Requires variant ID for listing. ```swift func loadPrices(variantId: String) async { do { let filter = URLQueryItem(name: "filter[variant_id]", value: variantId) let response = try await lemon.getPrices(queryItems: [filter]) for price in response.data { print("Price \(price.id): \(price.attributes.unitPrice) \(price.attributes.scheme)") } } catch { print("Error: \(error)") } } func loadSinglePrice(priceId: String) async { do { let response = try await lemon.getPrice(priceId) print("Unit price: \(response.data.attributes.unitPrice)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### Get License Keys with Default Pagination Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeys(pageNumber_pageSize_) Call this method to retrieve license keys with default pagination settings (page 1, 10 items per page). ```swift public func getLicenseKeys(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### Get Discounts with Pagination Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getDiscounts(pageNumber_pageSize_) Call this method to fetch a list of discounts. You can specify the page number and the number of items per page. Defaults to page 1 with 10 items per page. ```swift public func getDiscounts(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### Get Discounts with Default Parameters Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getDiscounts(pageNumber_pageSize_queryItems_) Call `getDiscounts` without arguments to retrieve the first page of discounts with the default page size. ```swift public func getDiscounts(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### Get Files with Pagination Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getFiles(pageNumber_pageSize_) Call this method to retrieve a paginated list of files. Default values are used if pageNumber or pageSize are not provided. ```swift public func getFiles(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### List and Get Webhooks in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieves a list of configured webhooks for a store, showing their URLs and the events they are subscribed to. Useful for integrating with external systems. Requires a store ID. ```swift func loadWebhooks(storeId: String) async { do { let filter = URLQueryItem(name: "filter[store_id]", value: storeId) let response = try await lemon.getWebhooks(queryItems: [filter]) for webhook in response.data { let a = webhook.attributes print("\(webhook.id): \(a.url) — events: \(a.events.joined(separator: ", "))") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### Get License Keys Method Signature Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeys(pageNumber_pageSize_queryItems_) This is the method signature for retrieving license keys. It supports optional page number, page size, and custom query items. ```swift public func getLicenseKeys(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### Get License Key Instance by ID (Swift) Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeyInstance(__) Use this function to retrieve a single license key instance. Requires the ID of the license key. ```swift public func getLicenseKeyInstance(_ licenseKeyInstanceId: LicenseKeyInstance.ID) ``` -------------------------------- ### Load and Print Affiliates Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches a list of affiliates with specified page size and number, then prints their IDs and emails. Ensure the `lemon` object is initialized before calling. ```swift func loadAffiliates() async { do { let response = try await lemon.getAffiliates(pageNumber: 1, pageSize: 10) for affiliate in response.data { print("\(affiliate.id): \(affiliate.attributes.email)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### Initialize LemonSqueezy with API Key Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/LemonSqueezy Initializes the `LemonSqueezy` SDK with your provided API key. Ensure the API key is kept secure. ```swift public init(_ apiKey: String) ``` -------------------------------- ### getVariant Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single variant by ID. ```APIDOC ## getVariant ### Description Get a single variant by ID. ### Method GET ### Endpoint `/v1/variants/:id` ``` -------------------------------- ### Get Products with Pagination Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getProducts(pageNumber_pageSize_) Call this method to retrieve a list of products. You can specify the page number and the number of items per page. Defaults to page 1 with 10 items per page. ```swift public func getProducts(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### getSubscription Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single subscription by ID. ```APIDOC ## getSubscription ### Description Get a single subscription by ID. ### Method GET ### Endpoint `/v1/subscriptions/:id` ``` -------------------------------- ### Get Order Items with Pagination Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getOrderItems(pageNumber_pageSize_) Retrieves a list of order items. Supports pagination with default values for page number and page size. ```swift public func getOrderItems(pageNumber: Int = 1, pageSize: Int = 10) ``` -------------------------------- ### Get License Key by ID in Swift Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKey(__) Call this function with the ID of the license key to retrieve it. It returns a response object containing the `LicenseKey`. ```swift public func getLicenseKey(_ licenseKeyId: LicenseKey.ID) ``` -------------------------------- ### getOrder Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single order by ID. ```APIDOC ## getOrder ### Description Get a single order by ID. ### Method GET ### Endpoint `/v1/orders/:id` ``` -------------------------------- ### getProducts Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Returns a list of products. ```APIDOC ## getProducts ### Description Returns a list of products. ### Method GET ### Endpoint `/v1/products` ### Query Parameters - **pageNumber** (integer) - Optional - The page number to retrieve. - **pageSize** (integer) - Optional - The number of items per page. - **queryItems** (object) - Optional - Additional query parameters. ``` -------------------------------- ### getDiscount Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single discount by ID. ```APIDOC ## getDiscount ### Description Get a single discount by ID. ### Method GET ### Endpoint `/v1/discounts/:id` ``` -------------------------------- ### Products - List Products / Get Single Product Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieves a list of all products in a store, with an option to filter by store ID. Also allows fetching a single product by its ID. ```APIDOC ## GET /v1/products ### Description Retrieve all products in your store, optionally filtering by store with a query item. Also allows fetching a single product by its ID. ### Method GET ### Endpoint /v1/products ### Parameters #### Query Parameters - **filter[store_id]** (string) - Optional - Filters products by the specified store ID. - **page[number]** (integer) - Optional - The page number to retrieve. - **page[size]** (integer) - Optional - The number of items per page. ### Request Example (List Products) ```swift func loadProducts(storeId: String) async { do { let filter = URLQueryItem(name: "filter[store_id]", value: storeId) let response = try await lemon.getProducts(pageNumber: 1, pageSize: 25, queryItems: [filter]) for product in response.data { print("\(product.id): \(product.attributes.name) — \(product.attributes.status)") } } catch { print("Error: \(error)") } } ``` ### Request Example (Get Single Product) ```swift func loadSingleProduct(productId: String) async { do { let response = try await lemon.getProduct(productId) let p = response.data.attributes print("Product: \(p.name), Price: \(p.priceFormatted ?? \"N/A\")") } catch { print("Error: \(error)") } } ``` ### Response (List Products) #### Success Response (200) - **data** (Array) - A list of product objects. - **meta** (PageMeta) - Pagination metadata. ### Response (Get Single Product) #### Success Response (200) - **data** (Product) - The product object. #### Response Example (Product) ```json { "data": { "type": "product", "id": "101", "attributes": { "name": "Basic Plan", "price_formatted": "$", "status": "published", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" } } } ``` ``` -------------------------------- ### LemonSqueezy Initializer Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/LemonSqueezy Initializes the LemonSqueezy SDK with an API key. ```APIDOC ## init(_:) ### Description Initializes the LemonSqueezy SDK with the provided API key. ### Parameters #### Path Parameters - **apiKey** (String) - Required - The API key for authentication. ``` -------------------------------- ### Get License Key Instance by ID Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeyInstance(__queryItems_) Retrieves a single license key instance using its ID. You can optionally pass query items for additional filtering or parameters. ```swift public func getLicenseKeyInstance(_ licenseKeyInstanceId: LicenseKeyInstance.ID, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### getCheckout Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single checkout by ID. ```APIDOC ## getCheckout ### Description Get a single checkout by ID. ### Method GET ### Endpoint `/v1/checkouts/:id` ``` -------------------------------- ### List and Update License Keys in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches a list of license keys for a given store and demonstrates how to update a specific key, such as increasing its activation limit. Requires a store ID. ```swift func manageLicenseKeys(storeId: String) async { do { let filter = URLQueryItem(name: "filter[store_id]", value: storeId) let response = try await lemon.getLicenseKeys(queryItems: [filter]) for key in response.data { let a = key.attributes print("\(key.id): \(a.key) — status: \(a.status), activations: \(a.activationsCount)/\(a.activationLimit ?? -1)") } // Update a key (e.g., increase activation limit) if let firstKeyId = response.data.first?.id { let updateBody: [String: Any] = [ "data": [ "type": "license-keys", "id": firstKeyId, "attributes": ["activation_limit": 10] ] ] let updated = try await lemon.updateLicenseKey(firstKeyId, body: updateBody) print("New limit: \(updated.data.attributes.activationLimit ?? 0)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### getOrderItem Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single order item by ID. ```APIDOC ## getOrderItem ### Description Get a single order item by ID. ### Method GET ### Endpoint `/v1/order-items/:id` ``` -------------------------------- ### getLicenseKey Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single license key by ID. ```APIDOC ## getLicenseKey ### Description Get a single license key by ID. ### Method GET ### Endpoint `/v1/license-keys/:id` ``` -------------------------------- ### Manage Subscription Items: Get, Update, Check Usage Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Shows how to retrieve subscription item details, update its quantity, and check current usage for metered billing. Requires a valid subscription item ID. ```swift func manageSubscriptionItem(itemId: String) async { do { // Retrieve item let item = try await lemon.getSubscriptionItem(itemId) print("Quantity: \(item.data.attributes.quantity)") // Update quantity let updateBody: [String: Any] = [ "data": [ "type": "subscription-items", "id": itemId, "attributes": ["quantity": 5] ] ] _ = try await lemon.updateSubscriptionItem(itemId, body: updateBody) // Check usage for usage-based items let usage = try await lemon.getSubscriptionItemCurrentUsage(itemId) print("Usage this period: \(usage.meta)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### getLicenseKeyInstances Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Returns a list of license key instances. ```APIDOC ## getLicenseKeyInstances ### Description Returns a list of license key instances. ### Method GET ### Endpoint `/v1/license-key-instances` ### Query Parameters - **pageNumber** (integer) - Optional - The page number to retrieve. - **pageSize** (integer) - Optional - The number of items per page. - **queryItems** (object) - Optional - Additional query parameters. ``` -------------------------------- ### getDiscountRedemption Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Get a single discount redemption by ID. ```APIDOC ## getDiscountRedemption ### Description Get a single discount redemption by ID. ### Method GET ### Endpoint `/v1/discount-redemptions/:id` ``` -------------------------------- ### Get Customers with Pagination and Query Items Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getCustomers(pageNumber_pageSize_queryItems_) Call this method to retrieve a paginated list of customers. You can specify the page number, the number of results per page, and additional query items for filtering. ```swift public func getCustomers(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### List and get order items Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function demonstrates how to retrieve a list of order items for a specific order. Order items represent individual line items within an order. ```APIDOC ## Order Items ### Description Fetches a list of order items associated with a given order. Each order item details a product purchased within that order. ### Method `getOrderItems(queryItems:)` ### Parameters #### Query Parameters - **filter[order_id]** (String) - Required - The ID of the order to filter order items by. ### Request Example ```json { "queryItems": [ { "name": "filter[order_id]", "value": "" } ] } ``` ### Response Example (Success) ```json { "data": [ { "id": "", "attributes": { "productId": "", "priceFormatted": "$19.99" // ... other attributes } } // ... other order items ] } ``` ``` -------------------------------- ### Instance CreatedAt Property Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/ActivateLicense_Instance Represents the creation timestamp of the license instance. ```swift public let createdAt: String ``` -------------------------------- ### Stores - Get Single Store Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieves details for a specific store by its ID. ```APIDOC ## GET /v1/stores/{id} ### Description Retrieves details for a single store by its ID. ### Method GET ### Endpoint /v1/stores/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the store. ### Request Example ```swift func loadStore(id: String) async { do { let response = try await lemon.getStore(id) let store = response.data print("Store: \(store.attributes.name), Currency: \(store.attributes.currency)") } catch { print("Error: \(error)") } } ``` ### Response #### Success Response (200) - **data** (Store) - The store object. #### Response Example ```json { "data": { "type": "store", "id": "1", "attributes": { "name": "My Awesome Store", "currency": "USD", "created_at": "2023-01-01T12:00:00Z", "updated_at": "2023-01-01T12:00:00Z" } } } ``` ``` -------------------------------- ### List / Get checkouts Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieve a list of checkouts or fetch a specific checkout by its ID. ```APIDOC ## List checkouts ### Description Retrieves a list of checkouts. ### Method `GET` ### Endpoint `/v1/checkouts` ### Query Parameters - **page[number]** (integer) - Optional - The page number to retrieve. - **page[size]** (integer) - Optional - The number of items per page. ### Response #### Success Response (200) - **data** (array) - An array of checkout objects. - **id** (string) - The unique identifier for the checkout. - **attributes** (object) - **expiresAt** (string) - The expiration date and time of the checkout. ### Request Example ```swift func loadCheckouts() async { do { let response = try await lemon.getCheckouts(pageNumber: 1, pageSize: 10) for checkout in response.data { print("\(checkout.id): expires \(checkout.attributes.expiresAt ?? "never")") } // Fetch a specific checkout if let firstId = response.data.first?.id { let single = try await lemon.getCheckout(firstId) print("URL: \(single.data.attributes.url)") } } catch { print("Error: \(error)") } } ``` ``` ```APIDOC ## Get a single checkout ### Description Retrieves a specific checkout by its unique identifier. ### Method `GET` ### Endpoint `/v1/checkouts/{checkout_id}` ### Parameters #### Path Parameters - **checkoutId** (string) - Required - The unique identifier of the checkout to retrieve. ### Response #### Success Response (200) - **data** (object) - The checkout object. - **attributes** (object) - **url** (string) - The URL of the checkout session. ### Request Example ```swift // This is part of the loadCheckouts function example above. if let firstId = response.data.first?.id { let single = try await lemon.getCheckout(firstId) print("URL: \(single.data.attributes.url)") } ``` ``` -------------------------------- ### Handle License Activation, Validation, and Deactivation in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Demonstrates the process of activating a license on a device, validating its status, and deactivating it. This is intended for end-user devices and does not require authentication. Requires the license key and optionally an instance ID. ```swift func handleLicense(key: String, instanceId: String?) async { do { // Activate on this device let activation = try await lemon.activateLicense( licenseKey: key, instanceName: UIDevice.current.name ) print("Activated: \(activation.activated)") print("Instance ID: \(activation.instance?.id ?? "N/A")") print("License status: \(activation.licenseKey?.status ?? "N/A")") // Validate (instanceId optional for single-activation keys) let validation = try await lemon.validateLicense( licenseKey: key, instanceId: activation.instance?.id ) print("Valid: \(validation.valid)") print("Customer: \(validation.meta?.customerName ?? "N/A")") // Deactivate when uninstalling if let iid = activation.instance?.id { let deactivation = try await lemon.deactivateLicense( licenseKey: key, instanceId: iid ) print("Deactivated: \(deactivation.deactivated)") } } catch { print("License error: \(error)") } } ``` -------------------------------- ### Get Subscription by ID Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getSubscription(__) Retrieves a single subscription object using its unique identifier. ```APIDOC ## getSubscription(_:) ### Description Get a single subscription by ID. ### Method Signature ```swift public func getSubscription(_ subscriptionId: Subscription.ID) ``` ### Parameters #### Path Parameters - **subscriptionId** (Subscription.ID) - Required - The ID of the subscription you'd like to retrieve. ### Returns A response object containing the requested `Subscription`. ``` -------------------------------- ### getLicenseKeyInstances(pageNumber:pageSize:queryItems:) Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getLicenseKeyInstances(pageNumber_pageSize_queryItems_) Returns a list of license key instances with optional pagination and query parameters. ```APIDOC ## getLicenseKeyInstances(pageNumber:pageSize:queryItems:) ### Description Returns a list of license key instances. ### Method Signature ```swift public func getLicenseKeyInstances(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` ### Parameters #### Query Parameters - **pageNumber** (Int) - Optional - The page number to return the response for. Defaults to 1. - **pageSize** (Int) - Optional - The number of resources to return per-page. Defaults to 10. - **queryItems** ([URLQueryItem]) - Optional - An array of `URLQueryItem`, passed as query parameters. ### Returns A response object containing an array of `LicenseKeyInstance`. ``` -------------------------------- ### Get a Single Variant Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches details for a specific variant by its ID. Includes error handling for the API request. ```swift func loadSingleVariant(variantId: String) async { do { let response = try await lemon.getVariant(variantId) print("Variant: \(response.data.attributes.name)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### Fetch All Pages with Pagination Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Implements a loop to fetch all pages of data using `pageNumber` and `pageSize`. It continues fetching until the `currentPage` exceeds the `lastPage` reported in the meta information. Assumes `lemon.getOrders` is available. ```swift func fetchAllPages() async { var currentPage = 1 var lastPage = 1 repeat { do { let response = try await lemon.getOrders(pageNumber: currentPage, pageSize: 50) if let page = response.meta?.page { lastPage = page.lastPage print("Fetched page \(page.currentPage)/\(page.lastPage), total: \(page.total)") } // Process response.data ... currentPage += 1 } catch { print("Error on page \(currentPage): \(error)") break } } while currentPage <= lastPage } ``` -------------------------------- ### List and Get Orders Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Retrieves a list of orders for a specific store, including pagination, or fetches a single order by its ID. Displays order details like user email, total, and status. ```swift func loadOrders(storeId: String) async { do { let filter = URLQueryItem(name: "filter[store_id]", value: storeId) let response = try await lemon.getOrders(pageNumber: 1, pageSize: 20, queryItems: [filter]) let meta = response.meta?.page print("Total orders: \(meta?.total ?? 0)") for order in response.data { let a = order.attributes print("Order \(order.id): \(a.userEmail) — \(a.totalFormatted) — \(a.status)") } } catch { print("Error: \(error)") } } func loadSingleOrder(orderId: String) async { do { let response = try await lemon.getOrder(orderId) let a = response.data.attributes print("Refunded: \(a.refunded), Subtotal: \(a.subtotalFormatted)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### Get a Single Store Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches details for a specific store by its ID. Includes error handling for the API request. ```swift func loadStore(id: String) async { do { let response = try await lemon.getStore(id) let store = response.data print("Store: \(store.attributes.name), Currency: \(store.attributes.currency)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### List and update license keys Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt This function demonstrates how to fetch a list of license keys filtered by store ID and how to update a specific license key, such as increasing its activation limit. ```APIDOC ## List and update license keys ### Description Fetches a list of license keys for a given store and demonstrates updating a license key's activation limit. ### Method `getLicenseKeys(queryItems:)` and `updateLicenseKey(_:body:)` ### Parameters #### Query Parameters for `getLicenseKeys` - **filter[store_id]** (String) - Required - The ID of the store to filter license keys by. #### Path Parameters for `updateLicenseKey` - **id** (String) - Required - The ID of the license key to update. #### Request Body for `updateLicenseKey` - **data.type** (String) - Required - Must be "license-keys". - **data.id** (String) - Required - The ID of the license key to update. - **data.attributes.activation_limit** (Integer) - Optional - The new activation limit for the license key. ### Request Example (Update) ```json { "data": { "type": "license-keys", "id": "", "attributes": { "activation_limit": 10 } } } ``` ### Response Example (Update Success) ```json { "data": { "type": "license-keys", "id": "", "attributes": { "activation_limit": 10 // ... other attributes } } } ``` ``` -------------------------------- ### getStore(_:) Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getStore(__) Retrieves a single store by its ID. This method is equivalent to making a GET request to the /v1/stores/:id endpoint. ```APIDOC ## GET /v1/stores/:id ### Description Return a single store. ### Method GET ### Endpoint `/v1/stores/:id` ### Parameters #### Path Parameters - **id** (Store.ID) - Required - The unique identifier of the store to retrieve. ### Response #### Success Response (200) - **data** (array of Store) - A response object containing an array of `Store`. ### Request Example ```swift public func getStore(_ storeId: Store.ID) ``` ### Response Example ```json { "data": [ { "id": 1, "name": "Example Store", "currency": "USD" } ] } ``` ``` -------------------------------- ### Get Discount by ID in Swift Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getDiscount(__) Call this function to retrieve a single discount by its ID. Ensure you have the correct Discount.ID. ```swift public func getDiscount(_ discountId: Discount.ID) ``` -------------------------------- ### Instance Structure Definition Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/ValidateLicense_Instance Defines the public structure 'Instance' which conforms to Codable. It includes properties for id, name, and createdAt. ```APIDOC ## Struct Instance ### Description Represents an instance with properties like ID, name, and creation timestamp. Conforms to `Codable` for data serialization and deserialization. ### Properties - **id** (String) - Required - The unique identifier for the instance. - **name** (String) - Required - The name of the instance. - **createdAt** (String) - Required - The timestamp indicating when the instance was created. ``` -------------------------------- ### getStore Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Return a single store. ```APIDOC ## getStore ### Description Return a single store. Equivalent to `GET /v1/stores/:id` ### Method GET ### Endpoint `/v1/stores/:id` ``` -------------------------------- ### Short License Key Property Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/LicenseKey_Attributes Provides a shortened representation of the license key, starting with 'XXXX-' followed by the last 12 characters. ```swift public let keyShort: String ``` -------------------------------- ### Instance Name Property Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/ActivateLicense_Instance Represents the name of the license instance. ```swift public let name: String ``` -------------------------------- ### getCustomers Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Returns a list of customers. ```APIDOC ## getCustomers ### Description Returns a list of customers. ### Method GET ### Endpoint `/v1/customers` ### Query Parameters - **pageNumber** (integer) - Optional - The page number to retrieve. - **pageSize** (integer) - Optional - The number of items per page. - **queryItems** (object) - Optional - Additional query parameters. ``` -------------------------------- ### List and Get Checkouts Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches a list of checkouts with pagination or retrieves a specific checkout by its ID. Useful for tracking checkout activity. ```swift func loadCheckouts() async { do { let response = try await lemon.getCheckouts(pageNumber: 1, pageSize: 10) for checkout in response.data { print("\(checkout.id): expires \(checkout.attributes.expiresAt ?? "never")") } // Fetch a specific checkout if let firstId = response.data.first?.id { let single = try await lemon.getCheckout(firstId) print("URL: \(single.data.attributes.url)") } } catch { print("Error: \(error)") } } ``` -------------------------------- ### Initialize LemonSqueezy Instance Source: https://github.com/lmsqueezy/lemonsqueezy-swift/blob/main/README.md Instantiate LemonSqueezy with your API key during app launch. Make the instance available throughout your app using EnvironmentObject. ```swift import LemonSqueezy @main struct Lemon_SqueezyApp: App { @StateObject var lemon = LemonSqueezy(LS_API_KEY) var body: some Scene { WindowGroup { ContentView() .environmentObject(lemon) } } } // Then use in any file by importing the following @EnvironmentObject var lemon: LemonSqueezy ``` -------------------------------- ### Get Stores Function Signature Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getStores(pageNumber_pageSize_queryItems_) This is the function signature for retrieving a list of stores. It supports optional pagination and custom query items. ```swift public func getStores(pageNumber: Int = 1, pageSize: Int = 10, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### Load Discounts and Redemptions in Swift Source: https://context7.com/lmsqueezy/lemonsqueezy-swift/llms.txt Fetches a list of discounts for a specific store and retrieves redemption data. Useful for managing promotional offers. Requires a store ID. ```swift func loadDiscounts(storeId: String) async { do { let filter = URLQueryItem(name: "filter[store_id]", value: storeId) let response = try await lemon.getDiscounts(pageNumber: 1, pageSize: 10, queryItems: [filter]) for discount in response.data { let a = discount.attributes print("\(discount.id): \(a.code) — \(a.amount)\(\(\("percent" == a.amountType) ? "%" : "¢")) — expires: \(a.expiresAt ?? "never")") } // Fetch redemptions let redemptions = try await lemon.getDiscountRedemptions(pageNumber: 1, pageSize: 20) print("Total redemptions: \(redemptions.meta?.page.total ?? 0)") } catch { print("Error: \(error)") } } ``` -------------------------------- ### activateLicense Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Home Activate a license key. ```APIDOC ## activateLicense ### Description Activate a license key. ### Method POST ### Endpoint `/v1/licenses/activate` ### Request Body - **licenseKey** (string) - Required - The license key to activate. - **instanceName** (string) - Optional - The name of the instance to associate with the license. ``` -------------------------------- ### Get a Single Store Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getStore(__queryItems_) Call this function to retrieve a specific store by its ID. You can optionally pass `URLQueryItem` objects to customize the request. ```swift public func getStore(_ storeId: Store.ID, queryItems: [URLQueryItem] = []) ``` -------------------------------- ### Get Subscription by ID in Swift Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/getSubscription(__) Use this function to retrieve a single subscription by its ID. Ensure you have the subscription's ID available. ```swift public func getSubscription(_ subscriptionId: Subscription.ID) ``` -------------------------------- ### activateLicense Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/activateLicense(licenseKey_instanceName_) Activates a license using the provided license key and instance name. ```APIDOC ## activateLicense(licenseKey:instanceName:) ### Description Activates a license using the provided license key and instance name. ### Method Signature ```swift public func activateLicense(licenseKey: String, instanceName: String) ``` ### Parameters #### Path Parameters - **licenseKey** (String) - Required - The license key to activate. - **instanceName** (String) - Required - The name of the instance to associate with the license. ``` -------------------------------- ### Trial Ends At Property Source: https://github.com/lmsqueezy/lemonsqueezy-swift/wiki/Subscription_Attributes If the subscription includes a free trial, this ISO-8601 formatted string specifies the trial's end date and time. ```swift public let trialEndsAt: String? ```