### Validate License with LemonSqueezyLicense in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense Provides an example of validating an existing license key and instance ID. It demonstrates checking the validity of the license and handling the response. ```swift do { let response = try await license.validate(key: "your-license-key", instanceId: "instance-id") if response.valid { print("License is valid!") } else { print("License is not valid: (response.licenseKey?.status ?? "Unknown status")") } } catch { print("An error occurred: (error)") } ``` -------------------------------- ### Activate License with LemonSqueezyLicense in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense Shows how to activate a license key for a new application instance using the activate method. It includes handling successful activation and potential failures. ```swift do { let response = try await license.activate(key: "your-license-key", instanceName: "User's Mac") if response.activated { print("License activated successfully!") print("Instance ID: (response.instance?.id ?? "N/A")") } else { print("License activation failed: (response.licenseKey?.status ?? "Unknown status")") } } catch { print("An error occurred: (error)") } ``` -------------------------------- ### Initialize LemonSqueezyLicense Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Create a new instance of the LemonSqueezyLicense client to interact with the Lemon Squeezy license API. ```APIDOC ## Initialize LemonSqueezyLicense ### Description Create a new instance of the LemonSqueezyLicense client to interact with the Lemon Squeezy license API. ### Method Initialization (Not an HTTP method) ### Endpoint N/A ### Request Example ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() ``` ### Response N/A ``` -------------------------------- ### Initialize LemonSqueezyLicense in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense Demonstrates how to import and initialize the LemonSqueezyLicense struct to begin interacting with the Lemon Squeezy License API. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() ``` -------------------------------- ### Initialize Lemon Squeezy License Client (Swift) Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Creates a new instance of the LemonSqueezyLicense client to interact with the Lemon Squeezy license API. This is the first step before performing any license management operations. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() ``` -------------------------------- ### Initialize LemonSqueezyLicense Instance Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense Creates a new instance of the `LemonSqueezyLicense` struct. This initializer does not require any parameters and sets up the object for subsequent API calls. ```swift init() ``` -------------------------------- ### Define ActivateResponse.Instance Struct in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/activateresponse/instance-swift Defines the ActivateResponse.Instance struct, which represents a license instance with properties like creation date, ID, and name. It conforms to Swift.Decodable for easy decoding from data. ```swift struct Instance { let createdAt: Date let id: String let name: String } ``` -------------------------------- ### Activate License Key with Lemon Squeezy (Swift) Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Activates a license key for a new application instance, returning an instance ID for future validation. It handles API communication and provides detailed responses about the license, instance, and customer metadata. Error handling for common API issues is included. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() do { let response = try await license.activate( key: "XXXX-XXXX-XXXX-XXXX", instanceName: "MacBook Pro - John's Computer" ) if response.activated { // Store the instance ID for future validations let instanceId = response.instance?.id ?? "" let instanceName = response.instance?.name ?? "" let createdAt = response.instance?.createdAt // Access license key information let status = response.licenseKey?.status // .active, .inactive, .expired, .disabled let activationLimit = response.licenseKey?.activationLimit ?? 0 let activationUsage = response.licenseKey?.activationUsage ?? 0 // Access customer and product metadata let customerName = response.meta?.customerName ?? "" let customerEmail = response.meta?.customerEmail ?? "" let productName = response.meta?.productName ?? "" let variantName = response.meta?.variantName ?? "" print("License activated successfully!") print("Instance ID: (instanceId)") print("Activations: (activationUsage)/(activationLimit)") } else { print("Activation failed: (response.licenseKey?.status ?? "Unknown")") } } catch let error as LemonSqueezyLicenseError { switch error { case .badServerResponse: print("Invalid server response format") case .serverError(let statusCode, let errorMessage): print("Server error (\(statusCode)): (errorMessage ?? "No details")") } } catch { print("Unexpected error: (error)") } ``` -------------------------------- ### Activate License Key with LemonSqueezyLicense Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense Activates a given license key for a specific instance name. This asynchronous method returns an `ActivateResponse` object containing the instance ID upon successful activation. It requires the license key and instance name as input. ```swift func activate(key: String, instanceName: String) async throws -> ActivateResponse ``` -------------------------------- ### Activate License Key in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense/activate%28key%3Ainstancename%3A%29 The activate(key:instanceName:) method is used to activate a license key. It takes the license key and an instance name as input and returns an ActivateResponse object. This method can throw a LemonSqueezyLicenseError if the activation process fails. ```swift @discardableResult func activate( key: String, instanceName: String ) async throws -> ActivateResponse ``` -------------------------------- ### Activate a License Key Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Activate a license key for a new application instance and receive an instance ID for future validation. This endpoint interacts with the Lemon Squeezy API to activate a provided license key. ```APIDOC ## Activate a License Key ### Description Activate a license key for a new application instance and receive an instance ID for future validation. This endpoint interacts with the Lemon Squeezy API to activate a provided license key. ### Method POST (Internal) ### Endpoint `/v1/licenses/activate` (Conceptual - handled by the SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **key** (String) - Required - The license key to activate. - **instanceName** (String) - Required - A descriptive name for the application instance (e.g., "MacBook Pro - John's Computer"). ### Request Example ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() do { let response = try await license.activate( key: "XXXX-XXXX-XXXX-XXXX", instanceName: "MacBook Pro - John's Computer" ) // ... handle response ... } catch { // ... handle error ... } ``` ### Response #### Success Response (200) - **activated** (Bool) - Indicates if the license was activated successfully. - **instance** (Object) - Information about the activated instance. - **id** (String) - The unique identifier for the instance. - **name** (String) - The name of the instance. - **createdAt** (String) - The timestamp when the instance was created. - **licenseKey** (Object) - Details about the activated license key. - **status** (String) - The status of the license key (e.g., "active", "inactive", "expired", "disabled"). - **activationLimit** (Int) - The maximum number of times the license can be activated. - **activationUsage** (Int) - The current number of activations for the license. - **meta** (Object) - Metadata associated with the activation. - **customerName** (String) - The name of the customer. - **customerEmail** (String) - The email of the customer. - **productName** (String) - The name of the product. - **variantName** (String) - The name of the product variant. #### Response Example ```json { "activated": true, "instance": { "id": "instance-123", "name": "MacBook Pro - John's Computer", "createdAt": "2023-10-27T10:00:00Z" }, "licenseKey": { "status": "active", "activationLimit": 5, "activationUsage": 1 }, "meta": { "customerName": "John Doe", "customerEmail": "john.doe@example.com", "productName": "Awesome App", "variantName": "Pro" } } ``` #### Error Handling - **LemonSqueezyLicenseError.badServerResponse**: If the server response is malformed. - **LemonSqueezyLicenseError.serverError(statusCode, errorMessage)**: For specific HTTP errors from the server. ``` -------------------------------- ### Swift License Management Flow with LemonSqueezyLicense Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Implements a complete license management workflow in Swift, including activating, validating, and deactivating licenses using the LemonSqueezyLicense library. It stores and retrieves license keys and instance IDs locally using UserDefaults. Dependencies include the LemonSqueezyLicense package. Input is a license key and device name for activation, and stored credentials for validation and deactivation. Outputs are boolean values indicating success or failure. ```swift import LemonSqueezyLicense class LicenseManager { private let license = LemonSqueezyLicense() private let instanceIdKey = "app.license.instanceId" private let licenseKeyKey = "app.license.key" // Activate new license func activateLicense(key: String, deviceName: String) async -> Bool { do { let response = try await license.activate( key: key, instanceName: deviceName ) if response.activated, let instanceId = response.instance?.id { // Store credentials locally UserDefaults.standard.set(instanceId, forKey: instanceIdKey) UserDefaults.standard.set(key, forKey: licenseKeyKey) print("License activated: (response.meta?.productName ?? "Unknown")") print("Customer: (response.meta?.customerName ?? "Unknown")") return true } return false } catch { print("Activation error: (error)") return false } } // Validate existing license func validateLicense() async -> Bool { guard let licenseKey = UserDefaults.standard.string(forKey: licenseKeyKey), let instanceId = UserDefaults.standard.string(forKey: instanceIdKey) else { return false } do { let response = try await license.validate( key: licenseKey, instanceId: instanceId ) if response.valid, response.licenseKey?.status == .active { return true } else { print("License no longer valid: (response.licenseKey?.status ?? "Unknown")") return false } } catch { print("Validation error: (error)") return false } } // Deactivate current license func deactivateLicense() async -> Bool { guard let licenseKey = UserDefaults.standard.string(forKey: licenseKeyKey), let instanceId = UserDefaults.standard.string(forKey: instanceIdKey) else { return false } do { let response = try await license.deactivate( key: licenseKey, instanceId: instanceId ) if response.deactivated { // Clear local storage UserDefaults.standard.removeObject(forKey: instanceIdKey) UserDefaults.standard.removeObject(forKey: licenseKeyKey) return true } return false } catch { print("Deactivation error: (error)") return false } } } // Usage let licenseManager = LicenseManager() // On app launch Task { let isValid = await licenseManager.validateLicense() if isValid { print("App licensed and ready") } else { print("Please enter a valid license key") } } // When user enters license key Task { let success = await licenseManager.activateLicense( key: "XXXX-XXXX-XXXX-XXXX", deviceName: Host.current().localizedName ?? "Unknown Device" ) if success { print("License activated successfully") } } // When user deactivates Task { let success = await licenseManager.deactivateLicense() if success { print("License deactivated") } } ``` -------------------------------- ### ActivateResponse Struct Definition (Swift) Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/activateresponse Defines the ActivateResponse struct used for license activation responses. It includes properties for activation status, instance details, license key, and metadata. This struct conforms to Swift.Decodable for JSON parsing. ```swift struct ActivateResponse { let activated: Bool let instance: ActivateResponse.Instance? let licenseKey: ActivateResponse.LicenseKey? let meta: ActivateResponse.Meta? } ``` -------------------------------- ### Handle LemonSqueezyLicense Errors in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense Demonstrates robust error handling for API interactions using `LemonSqueezyLicenseError`. It shows how to catch specific errors like bad server responses or server-side issues. ```swift do { let response = try await license.activate(key: "your-license-key", instanceName: "User's Mac") // Handle successful response } catch let error as LemonSqueezyLicenseError { switch error { case .badServerResponse: print("Received an invalid response from the server") case .serverError(let statusCode, let errorMessage): print("Server error (status (statusCode)): (errorMessage ?? "No error message provided")") } } catch { print("An unexpected error occurred: (error)") } ``` -------------------------------- ### Swift Instance Struct Definition Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/deactivateresponse/instance-swift Defines the 'Instance' struct which represents a deactivated license. This structure is Decodable, allowing it to be initialized from data. ```swift struct Instance ``` -------------------------------- ### Deactivate License Instance with LemonSqueezyLicense (Swift) Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Demonstrates how to deactivate a specific license instance using the LemonSqueezyLicense library. This frees up an activation slot. It includes error handling for common license-related issues and checks the response for successful deactivation and updated activation counts. Dependencies include the `LemonSqueezyLicense` framework. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() let storedInstanceId = "instance-abc123" do { let response = try await license.deactivate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: storedInstanceId ) if response.deactivated { // Successfully deactivated let instanceId = response.instance?.id ?? "" let instanceName = response.instance?.name ?? "" // Check updated activation counts let activationUsage = response.licenseKey?.activationUsage ?? 0 let activationLimit = response.licenseKey?.activationLimit ?? 0 print("License deactivated successfully!") print("Deactivated instance: \(instanceName)") print("Remaining activations: \(activationLimit - activationUsage)") // Clear local license storage // UserDefaults.standard.removeObject(forKey: "instanceId") } else { let status = response.licenseKey?.status ?? "Unknown" print("Deactivation failed: \(status)") } } catch let error as LemonSqueezyLicenseError { switch error { case .badServerResponse: print("Invalid server response") case .serverError(let statusCode, let errorMessage): print("Server error (\(statusCode)): \(errorMessage ?? "No details")") } } catch { print("Unexpected error: \(error)") } ``` -------------------------------- ### LemonSqueezyLicense Struct Definition Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense Defines the `LemonSqueezyLicense` struct, serving as the primary interface for interacting with the Lemon Squeezy license API. This struct encapsulates methods for license management operations. ```swift struct LemonSqueezyLicense ``` -------------------------------- ### Validate License Key or Instance (Swift) Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense/validate%28key%3Ainstanceid%3A%29 This method validates a license key, optionally for a specific instance. It takes the license key as a String and an optional instanceId as a String. It returns a ValidateResponse upon success and can throw a LemonSqueezyLicenseError on failure. This is useful for checking the validity and status of a user's license. ```swift @discardableResult func validate( key: String, instanceId: String? = nil ) async throws -> ValidateResponse ``` -------------------------------- ### Define ActivateResponse.LicenseKey Struct Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/activateresponse/licensekey-swift This Swift code defines the ActivateResponse.LicenseKey struct, which models a license key's data. It includes properties for activation limits, usage, creation and expiration dates, the license key itself, and its status. This struct conforms to the Decodable protocol. ```swift struct LicenseKey ``` -------------------------------- ### Validate a License Key Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Validate an existing license key and optionally check a specific instance to ensure it's still valid. This endpoint interacts with the Lemon Squeezy API to verify the status of a license. ```APIDOC ## Validate a License Key ### Description Validate an existing license key and optionally check a specific instance to ensure it's still valid. This endpoint interacts with the Lemon Squeezy API to verify the status of a license. ### Method POST (Internal) ### Endpoint `/v1/licenses/validate` (Conceptual - handled by the SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **key** (String) - Required - The license key to validate. - **instanceId** (String?) - Optional - The ID of the instance to validate against. If nil, only the key's validity is checked. ### Request Example ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() let storedInstanceId = "instance-abc123" do { // Validate with instance ID let response = try await license.validate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: storedInstanceId ) // ... handle response ... // Validate without instance ID let keyOnlyResponse = try await license.validate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: nil ) // ... handle response ... } catch { // ... handle error ... } ``` ### Response #### Success Response (200) - **valid** (Bool) - Indicates if the license is valid for the given parameters. - **licenseKey** (Object) - Details about the license key. - **status** (String) - The status of the license key (e.g., "active", "inactive", "expired", "disabled"). - **activationUsage** (Int) - The current number of activations. - **activationLimit** (Int) - The maximum number of activations. - **instance** (Object?) - Information about the validated instance (if instanceId was provided and valid). - **name** (String) - The name of the instance. - **createdAt** (String) - The timestamp when the instance was created. - **meta** (Object) - Metadata associated with the validation. - **productName** (String) - The name of the product. - **customerName** (String) - The name of the customer. - **orderId** (Int) - The ID of the order associated with the license. #### Response Example ```json { "valid": true, "licenseKey": { "status": "active", "activationUsage": 1, "activationLimit": 5 }, "instance": { "name": "MacBook Pro - John's Computer", "createdAt": "2023-10-27T10:00:00Z" }, "meta": { "productName": "Awesome App", "customerName": "John Doe", "orderId": 12345 } } ``` #### Response Example (Key Only Validation) ```json { "valid": true, "licenseKey": { "status": "active", "activationUsage": 1, "activationLimit": 5 }, "meta": { "productName": "Awesome App", "customerName": "John Doe", "orderId": 12345 } } ``` #### Error Handling - **LemonSqueezyLicenseError.badServerResponse**: If the server response is malformed. - **LemonSqueezyLicenseError.serverError(statusCode, errorMessage)**: For specific HTTP errors from the server. ``` -------------------------------- ### Handle License Key Status with LemonSqueezyLicense (Swift) Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Illustrates how to validate a license key and handle its status using the LemonSqueezyLicense library. It checks for statuses like active, inactive, expired, and disabled, allowing for appropriate user feedback or app behavior. The code also verifies activation limits. Dependencies include the `LemonSqueezyLicense` framework. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() do { let response = try await license.validate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: "instance-abc123" ) if let status = response.licenseKey?.status { switch status { case .active: print("License is active and ready to use") // Allow full app functionality case .inactive: print("License is inactive") // Prompt user to activate or contact support case .expired: print("License has expired") // Show renewal/upgrade options case .disabled: print("License has been disabled") // Contact support or show error message } } // Check activation limits if let usage = response.licenseKey?.activationUsage, let limit = response.licenseKey?.activationLimit { if usage >= limit { print("Maximum activations reached (\(usage)/\(limit))") // Inform user to deactivate unused instances } else { print("Activations available: \(limit - usage)") } } } catch { print("Error checking license: \(error)") } ``` -------------------------------- ### Validate License Key with Lemon Squeezy (Swift) Source: https://context7.com/context7/kevinhermawan_github_io_swift-lemon-squeezy-license/llms.txt Validates an existing license key, optionally checking against a specific instance ID. This function allows for verifying license status and retrieving associated product and customer details. It supports validation with or without an instance ID and includes error handling for API responses. ```swift import LemonSqueezyLicense let license = LemonSqueezyLicense() let storedInstanceId = "instance-abc123" // Retrieved from previous activation do { // Validate with instance ID let response = try await license.validate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: storedInstanceId ) if response.valid { // License is valid - allow app to run let status = response.licenseKey?.status let activationUsage = response.licenseKey?.activationUsage ?? 0 let activationLimit = response.licenseKey?.activationLimit ?? 0 // Check instance details let instanceName = response.instance?.name ?? "" let instanceCreatedAt = response.instance?.createdAt // Access product and customer information let productName = response.meta?.productName ?? "" let customerName = response.meta?.customerName ?? "" let orderNumber = response.meta?.orderId ?? 0 print("License is valid!") print("Status: (status ?? "Unknown")") print("Instance: (instanceName)") print("Product: (productName)") } else { // License is invalid - deny access let reason = response.licenseKey?.status ?? "Unknown" print("License validation failed: (reason)") // Prompt user to enter valid license or purchase } // Validate without instance ID (checks key only, not specific instance) let keyOnlyResponse = try await license.validate( key: "XXXX-XXXX-XXXX-XXXX", instanceId: nil ) if keyOnlyResponse.valid { print("License key is valid (no instance check)") } } catch let error as LemonSqueezyLicenseError { switch error { case .badServerResponse: print("Invalid server response") case .serverError(let statusCode, let errorMessage): print("Server error (\(statusCode)): (errorMessage ?? "No details")") } } catch { print("Unexpected error: (error)") } ``` -------------------------------- ### Deactivate License with LemonSqueezyLicense in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense Illustrates how to deactivate a license key for a specific instance ID. It covers handling successful deactivation and potential issues. ```swift do { let response = try await license.deactivate(key: "your-license-key", instanceId: "instance-id") if response.deactivated { print("License deactivated successfully!") } else { print("License deactivation failed: (response.licenseKey?.status ?? "Unknown status")") } } catch { print("An error occurred: (error)") } ``` -------------------------------- ### Swift Decodable Struct for License Instance Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/validateresponse/instance-swift Defines the `Instance` struct conforming to Swift.Decodable for parsing validated license data. It includes properties for creation date, unique identifier, and instance name. This struct is essential for deserializing JSON responses related to license validation. ```swift struct Instance ``` -------------------------------- ### Swift DeactivateResponse.Meta Struct Definition Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/deactivateresponse/meta-swift Defines the Meta struct for license deactivation responses. It includes properties for customer, order, product, and store information. This struct is decodable from JSON. ```swift struct Meta { let customerEmail: String let customerId: Int let customerName: String let orderId: Int let orderItemId: Int let productId: Int let productName: String let storeId: Int let variantId: Int let variantName: String } ``` -------------------------------- ### Define LicenseKey Struct - Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/deactivateresponse/licensekey-swift Defines the `LicenseKey` struct used to represent a license key. This struct conforms to `Decodable` for easy parsing from JSON responses. ```swift struct LicenseKey enum Status ``` -------------------------------- ### Validate License Key with LemonSqueezyLicense Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense Validates a license key, optionally for a specific instance ID. This asynchronous method takes the license key and an optional instance ID, returning a `ValidateResponse` indicating the validation status. It can be used to check the general validity of a key or its status for a particular instance. ```swift func validate(key: String, instanceId: String?) async throws -> ValidateResponse ``` -------------------------------- ### Define ValidateResponse Struct in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/validateresponse Defines the ValidateResponse struct, a model for license validation responses. It includes properties for instance, license key, meta information, and a validity flag. This struct conforms to Swift.Decodable. ```swift struct ValidateResponse { let instance: ValidateResponse.Instance? let licenseKey: ValidateResponse.LicenseKey? let meta: ValidateResponse.Meta? let valid: Bool struct Instance { // Properties for instance details } struct LicenseKey { // Properties for license key details } struct Meta { // Properties for metadata } init(from decoder: any Decoder) throws { // Initializer implementation self.instance = nil self.licenseKey = nil self.meta = nil self.valid = false } } ``` -------------------------------- ### Deactivate License Key (Swift) Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense/deactivate%28key%3Ainstanceid%3A%29 Deactivates a specific license key for a given instance ID. This method requires the license key and the instance ID obtained during activation. It returns a `DeactivateResponse` upon successful deactivation or throws a `LemonSqueezyLicenseError` if the operation fails. ```swift @discardableResult func deactivate( key: String, instanceId: String ) async throws -> DeactivateResponse ``` -------------------------------- ### Swift ValidateResponse.Meta Struct Definition Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/validateresponse/meta-swift Defines the ValidateResponse.Meta struct, used to hold metadata for license validation. It includes properties like customer email, ID, name, order details, product details, store ID, and variant information. This struct conforms to the Swift.Decodable protocol, allowing it to be decoded from external data. ```swift struct Meta { let customerEmail: String let customerId: Int let customerName: String let orderId: Int let orderItemId: Int let productId: Int let productName: String let storeId: Int let variantId: Int let variantName: String } ``` -------------------------------- ### Swift DeactivateResponse Struct Definition Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/deactivateresponse Defines the DeactivateResponse struct used to model the response from a license deactivation request. It includes properties for deactivation status, instance details, license key information, and metadata. This struct conforms to the Decodable protocol. ```swift struct DeactivateResponse struct Instance struct LicenseKey struct Meta let deactivated: Bool let instance: DeactivateResponse.Instance? let licenseKey: DeactivateResponse.LicenseKey? let meta: DeactivateResponse.Meta? init(from: any Decoder) throws ``` -------------------------------- ### Deactivate License Key with LemonSqueezyLicense Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicense Deactivates a license key associated with a specific instance ID. This asynchronous method requires the license key and instance ID as parameters and returns a `DeactivateResponse` upon successful deactivation. ```swift func deactivate(key: String, instanceId: String) async throws -> DeactivateResponse ``` -------------------------------- ### Swift Enum Definition for License Key Status Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/deactivateresponse/licensekey-swift.struct/status-swift Defines the 'Status' enumeration to represent the different states of a license key. This enum is useful for managing and checking the validity of license keys within the application. It conforms to several Swift protocols for enhanced functionality. ```swift enum Status { case active case disabled case expired case inactive } ``` -------------------------------- ### Define LemonSqueezyLicenseError Enum in Swift Source: https://kevinhermawan.github.io/swift-lemon-squeezy-license/documentation/lemonsqueezylicense/lemonsqueezylicenseerror This Swift enum defines possible errors when interacting with the Lemon Squeezy License API. It includes cases for bad server responses and server errors with associated status codes and messages. It conforms to Swift.Error and Swift.Sendable. ```swift enum LemonSqueezyLicenseError ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.