### Install Lemon Squeezy PHP Package via Composer Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md Install the Lemon Squeezy PHP SDK using Composer package manager. This command downloads the package and adds it as a dependency to your project. ```bash composer require seisigmasrl/lemonsqueezy-php ``` -------------------------------- ### Initialize and Authenticate Lemon Squeezy PHP Client Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Shows the basic setup required for using the Lemon Squeezy PHP SDK, including autoloader inclusion and client initialization with API token authentication. This is the foundation for all subsequent API calls and must be performed before using any SDK functionality. ```php authenticate('your_api_token_here'); ``` -------------------------------- ### Handle Resource Not Found Errors in Lemon Squeezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Shows how to catch ResourceNotFoundException when attempting to retrieve a non-existent resource, such as a customer with an invalid ID. The example gracefully handles the error and allows the application to continue with alternative logic instead of terminating. ```php customer()->getCustomer($customerId); } catch (ResourceNotFoundException $e) { echo "Customer with ID " . $customerId . " does not exist.\n"; // Continue with alternative logic } ``` -------------------------------- ### Handle Authentication Errors in Lemon Squeezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Demonstrates catching and handling UnauthorizedPermissionException when authentication fails due to invalid API tokens. The example retrieves user information and logs the error message while providing user-friendly feedback. This is essential for applications requiring API authentication validation. ```php authenticate('your_api_token_here'); try { $user = $client->user()->getUserInformation(); } catch (UnauthorizedPermissionException $e) { error_log("Authentication failed: " . $e->getMessage()); echo "Please check your API token and try again.\n"; exit(1); } ``` -------------------------------- ### List and Get Store Information in PHP Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md Retrieve all stores or get details for a specific store by ID. The store endpoint provides access to store objects as defined in the Lemon Squeezy API documentation. ```php store(); $storeList = $lemonSqueeze->getAllStores(); // List all existing Stores $store = $lemonSqueeze->getStore(12685); // Get details of the store with the ID: 12685 ``` -------------------------------- ### List and Get Customer Information in PHP Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md Retrieve all customers, customers from a specific store, or a specific customer by ID. The customer endpoint provides access to customer objects and filtering capabilities as defined in the Lemon Squeezy API documentation. ```php customer(); $allCustomers = $lemonSqueeze->getAllCustomers(); // List all existing Customers $storeCustomers = $lemonSqueeze->getStoreCustomers(12689); // List all customers from the Store ID: 12689 $customer = $lemonSqueeze->getCustomer(596510); // Get the details of the Customer with the ID: 596510 ``` -------------------------------- ### Handle Rate Limiting in Lemon Squeezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Demonstrates catching ApiLimitExceededException when API rate limits are exceeded. The example implements a basic wait strategy using sleep() before retrying. This prevents application crashes during high-volume API usage and allows for graceful rate limit handling. ```php product()->getAllProducts(); } catch (ApiLimitExceededException $e) { echo "API rate limit exceeded. Please wait before retrying.\n"; // Implement exponential backoff sleep(60); // Retry logic here } ``` -------------------------------- ### Get User Information in PHP Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md Retrieve authenticated user information from Lemon Squeezy API. Returns a User entity object containing user details like ID, name, email, avatar URL, and timestamps. The deprecated getUserId() method has been replaced with direct ID property access. ```php user(); $userDetails = $user->getUserInformation(); var_dump($userDetails); // object(LemonSqueezy\Entity\User)#4567 (7) { // ["id"]=> id(5) "13546" // ["name"]=> string(14) "Marco Polo" // ["email"]=> string(19) "marco@polo.com" // ["color"]=> string(7) "#7047EB" // ["avatar_url"]=> string(72) "https://www.gravatar.com/avatar/cc27e9f9e9a66d0fb6a988a?d=blank" // ["has_custom_avatar"]=> bool(false) // ["createdAt"]=> string(27) "2023-01-18T13:56:46.000000Z" // ["updatedAt"]=> string(27) "2023-01-18T14:00:01.000000Z" // } ``` -------------------------------- ### List All Products - LemonSqueezy PHP SDK Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Retrieves all products across all stores with comprehensive details including name, slug, status, pricing information, and metadata. Supports both fixed pricing and pay-what-you-want models with formatted price display. Includes thumbnail URLs and purchase links while handling API errors gracefully. ```php authenticate('your_api_token_here'); try { $products = $client->product()->getAllProducts(); foreach ($products as $product) { echo "Product ID: " . $product->id . "\n"; echo "Store ID: " . $product->store_id . "\n"; echo "Name: " . $product->name . "\n"; echo "Slug: " . $product->slug . "\n"; echo "Status: " . $product->status->value . " (" . $product->status_formatted . ")\n"; if ($product->description) { echo "Description: " . substr($product->description, 0, 100) . "...\n"; } // Pricing information if ($product->pay_what_you_want) { echo "Pricing: Pay What You Want\n"; echo " From: " . $product->from_price . "\n"; echo " To: " . $product->to_price . "\n"; } else { echo "Price: " . $product->price_formatted . "\n"; } if ($product->buy_now_url) { echo "Buy Now: " . $product->buy_now_url . "\n"; } if ($product->thumb_url) { echo "Thumbnail: " . $product->thumb_url . "\n"; } echo "Created: " . $product->created_at . "\n"; echo "---\n"; } echo "Total products: " . count($products) . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Manage Products with Lemon Squeezy PHP SDK Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md This snippet shows how to initialize the SDK and perform various product-related operations. It fetches all products, products from a specific store, a single product's details, its variants, and a product with its variants. Requires the Lemon Squeezy PHP SDK and a configured API client. ```php $lemonSqueeze = $client->product(); $allProducts = $lemonSqueeze->getAllProducts(); // List all existing Products $storeCustomers = $lemonSqueeze->getStoreProducts(12689); // List all Products from the Store ID: 12689 $product = $lemonSqueeze->getProduct(59920); // Get the details of the Products with the ID: 59920 $productVariants = $lemonSqueeze->getProductVariants(59920); // Get all Variants from the Product ID: 59920 $productWithVariants = $lemonSqueeze->getProductWithVariants(59920); // Get a Product with All their Variants ``` -------------------------------- ### Initialize and Authenticate Lemon Squeezy PHP Client Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Create a new Lemon Squeezy client instance and authenticate using an API token from the dashboard. Supports both default HTTP client and custom PSR-18 compliant HTTP clients. Demonstrates access to last response for debugging purposes. ```PHP authenticate('your_api_token_here'); // Optional: Create client with custom HTTP client use Symfony\Component\HttpClient\Psr18Client; $httpClient = new Psr18Client(); $client = LemonSqueezy::createWithHttpClient($httpClient); $client->authenticate('your_api_token_here'); // Access the last response for debugging $client->user()->getUserInformation(); $lastResponse = $client->getLastResponse(); echo $lastResponse->getStatusCode(); // 200 ``` -------------------------------- ### List All Stores with Sales and Revenue Statistics Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Retrieve all stores associated with the authenticated account including store metadata, plan information, country/currency details, and sales/revenue statistics for current and 30-day periods. Iterates through store collection and displays formatted output. ```PHP authenticate('your_api_token_here'); try { $stores = $client->store()->getAllStores(); foreach ($stores as $store) { echo "Store ID: " . $store->id . "\n"; echo "Name: " . $store->name . "\n"; echo "Slug: " . $store->slug . "\n"; echo "Domain: " . $store->domain . "\n"; echo "URL: " . $store->url . "\n"; echo "Plan: " . $store->plan . "\n"; echo "Country: " . $store->country_nicename . " (" . $store->country . ")\n"; echo "Currency: " . $store->currency . "\n"; echo "Total Sales: " . $store->total_sales . "\n"; echo "Total Revenue: " . $store->total_revenue . "\n"; echo "30-Day Sales: " . $store->thirty_day_sales . "\n"; echo "30-Day Revenue: " . $store->thirty_day_revenue . "\n"; echo "Created: " . $store->created_at . "\n"; echo "---\n"; } echo "Total stores: " . count($stores) . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error retrieving stores: " . $e->getMessage(); } ``` -------------------------------- ### Retrieve Product with All Variants using PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetches a product and all its associated variants in a single API call, optimizing performance by reducing redundant requests. This method requires the LemonSqueezy SDK and authentication. It outputs the product's main details and then iterates through each variant, displaying its specific information. ```php authenticate('your_api_token_here'); $productId = 59920; try { $product = $client->product()->getProductWithVariants($productId); echo "Product: " . $product->name . "\n"; echo "Base Price: " . $product->price_formatted . "\n"; echo "Status: " . $product->status_formatted . "\n\n"; if ($product->variants && count($product->variants) > 0) { echo "Available Variants:\n"; echo "===================\n"; foreach ($product->variants as $variant) { echo "\n" . $variant->name . "\n"; echo " ID: " . $variant->id . "\n"; echo " Price: " . $variant->price_formatted . "\n"; echo " Status: " . $variant->status_formatted . "\n"; if ($variant->slug) { echo " Slug: " . $variant->slug . "\n"; } } echo "\nTotal variants: " . count($product->variants) . "\n"; } else { echo "No variants available for this product.\n"; } // Display purchase options echo "\nPurchase Options:\n"; if ($product->buy_now_url) { echo "Direct purchase: " . $product->buy_now_url . "\n"; } } catch (\LemonSqueezy\Exception\ResourceNotFoundException $e) { echo "Product not found with ID: " . $productId . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### List Products by Store - LemonSqueezy PHP SDK Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Filters and retrieves all products for a specific store by store ID, categorizing them by publication status (published vs. draft). Displays product names with status indicators, pricing, and purchase links while maintaining a summary count of active and draft products. ```php authenticate('your_api_token_here'); $storeId = 12689; try { $products = $client->product()->getStoreProducts($storeId); echo "Products for Store ID: " . $storeId . "\n\n"; $activeProducts = 0; $draftProducts = 0; foreach ($products as $product) { echo $product->name; if ($product->status->value === 'published') { echo " ✓ "; $activeProducts++; } else { echo " (Draft) "; $draftProducts++; } echo $product->price_formatted . "\n"; if ($product->buy_now_url) { echo " Link: " . $product->buy_now_url . "\n"; } } echo "\nSummary:\n"; echo "Total Products: " . count($products) . "\n"; echo "Active: " . $activeProducts . "\n"; echo "Draft: " . $draftProducts . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Initialize and Authenticate Lemon Squeezy Client in PHP Source: https://github.com/seisigmasrl/lemonsqueezy.php/blob/main/README.md Create a new LemonSqueezy client instance and authenticate it using an API token. The API token can be generated from the Lemon Squeezy settings page. This initialization is required before making any API calls. ```php authenticate('yourApiToken'); ``` -------------------------------- ### Retrieve Single Product Details using PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetches detailed information for a specific product using its ID. It requires the 'vendor/autoload.php' and the 'LemonSqueezy' namespace. The function takes a product ID and returns an object containing product details, or throws exceptions for not found or general errors. ```php authenticate('your_api_token_here'); $productId = 59920; try { $product = $client->product()->getProduct($productId); echo "Product Details:\n"; echo "================\n"; echo "ID: " . $product->id . "\n"; echo "Store ID: " . $product->store_id . "\n"; echo "Name: " . $product->name . "\n"; echo "Slug: " . $product->slug . "\n"; echo "Status: " . $product->status_formatted . "\n\n"; if ($product->description) { echo "Description:\n" . $product->description . "\n\n"; } echo "Pricing:\n"; if ($product->pay_what_you_want) { echo " Type: Pay What You Want\n"; echo " Suggested Range: " . $product->from_price . " - " . $product->to_price . "\n"; } else { echo " Price: " . $product->price_formatted . "\n"; } echo "\nImages:\n"; if ($product->thumb_url) { echo " Thumbnail: " . $product->thumb_url . "\n"; } if ($product->large_thumb_url) { echo " Large Thumbnail: " . $product->large_thumb_url . "\n"; } if ($product->buy_now_url) { echo "\nBuy Now URL: " . $product->buy_now_url . "\n"; } echo "\nTimestamps:\n"; echo " Created: " . $product->created_at . "\n"; echo " Updated: " . $product->updated_at . "\n"; } catch (\LemonSqueezy\Exception\ResourceNotFoundException $e) { echo "Product not found with ID: " . $productId . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### List All Customers with Revenue Metrics in LemonSqueezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Retrieves all customers across all stores using the LemonSqueezy PHP client with comprehensive customer data including status enums, location information, and financial metrics (total revenue and MRR). Iterates through each customer displaying formatted currency values and location data when available, with error handling for API exceptions. ```php authenticate('your_api_token_here'); try { $customers = $client->customer()->getAllCustomers(); foreach ($customers as $customer) { echo "Customer ID: " . $customer->id . "\n"; echo "Store ID: " . $customer->store_id . "\n"; echo "Name: " . $customer->name . "\n"; echo "Email: " . $customer->email . "\n"; echo "Status: " . $customer->status->value . "\n"; // Enum value echo "Status (formatted): " . $customer->status_formatted . "\n"; // Location information (may be null) if ($customer->city) { echo "Location: " . $customer->city . ", " . $customer->region . ", " . $customer->country_formatted . "\n"; } // Revenue metrics echo "Total Revenue: " . $customer->total_revenue_currency_formatted . "\n"; echo "MRR: " . $customer->mrr_formatted . "\n"; echo "Test Mode: " . ($customer->test_mode ? 'Yes' : 'No') . "\n"; echo "Created: " . $customer->created_at . "\n"; echo "---\n"; } echo "Total customers: " . count($customers) . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Retrieve Single Store Details with LemonSqueezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetches detailed information about a specific store by ID using the LemonSqueezy PHP client. Returns store metadata including ID, name, slug, domain, avatar URL, and currency. Constructs a dashboard URL for direct store access and handles ResourceNotFoundException and ErrorException for robust error management. ```php authenticate('your_api_token_here'); $storeId = 12685; try { $store = $client->store()->getStore($storeId); echo "Store Details:\n"; echo " ID: " . $store->id . "\n"; echo " Name: " . $store->name . "\n"; echo " Slug: " . $store->slug . "\n"; echo " Domain: " . $store->domain . "\n"; echo " Avatar: " . $store->avatar_url . "\n"; echo " Currency: " . $store->currency . "\n"; // Build store dashboard URL $dashboardUrl = "https://app.lemonsqueezy.com/stores/" . $store->id; echo " Dashboard: " . $dashboardUrl . "\n"; } catch (\LemonSqueezy\Exception\ResourceNotFoundException $e) { echo "Store not found with ID: " . $storeId . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### List Customers by Store with Revenue Aggregation in LemonSqueezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Queries all customers for a specific store ID using the LemonSqueezy PHP client, enabling store-specific analytics and reporting. Aggregates total revenue and MRR across all store customers, displaying individual customer metrics and combined financial summaries with formatted currency values. ```php authenticate('your_api_token_here'); $storeId = 12689; try { $customers = $client->customer()->getStoreCustomers($storeId); echo "Customers for Store ID: " . $storeId . "\n\n"; $totalRevenue = 0; $totalMrr = 0; foreach ($customers as $customer) { echo $customer->name . " (" . $customer->email . ")\n"; echo " Revenue: " . $customer->total_revenue_currency_formatted . "\n"; echo " MRR: " . $customer->mrr_formatted . "\n"; $totalRevenue += $customer->total_revenue_currency; $totalMrr += $customer->mrr; } echo "\nSummary:\n"; echo "Total Customers: " . count($customers) . "\n"; echo "Combined Revenue: $" . number_format($totalRevenue / 100, 2) . "\n"; echo "Combined MRR: $" . number_format($totalMrr / 100, 2) . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Implement Retry Logic with Exponential Backoff in Lemon Squeezy PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Provides a comprehensive retry function that handles multiple exception types with exponential backoff strategy. It attempts to retrieve a store resource up to a maximum number of retries, handling rate limits with progressive delays, returning null for non-existent resources, and re-throwing API errors after logging. This pattern is essential for production-grade API integration. ```php store()->getStore($storeId); } catch (ApiLimitExceededException $e) { $attempt++; if ($attempt >= $maxRetries) { throw $e; } sleep(pow(2, $attempt)); // Exponential backoff } catch (ResourceNotFoundException $e) { return null; // Store doesn't exist } catch (ErrorException $e) { error_log("API Error: " . $e->getMessage()); throw $e; } } } try { $store = getStoreWithRetry($client, 12685); if ($store) { echo "Store found: " . $store->name . "\n"; } else { echo "Store not found.\n"; } } catch (ErrorException $e) { echo "Failed to retrieve store after multiple attempts.\n"; } ``` -------------------------------- ### Retrieve Authenticated User Information with Error Handling Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetch the currently authenticated user's account details including ID, name, email, avatar URL, and timestamps. Includes comprehensive error handling for authentication failures and API errors with try-catch blocks. ```PHP authenticate('your_api_token_here'); try { $user = $client->user()->getUserInformation(); // Access user properties echo "User ID: " . $user->id . "\n"; echo "Name: " . $user->name . "\n"; echo "Email: " . $user->email . "\n"; echo "Color: " . $user->color . "\n"; echo "Avatar URL: " . $user->avatar_url . "\n"; echo "Has Custom Avatar: " . ($user->has_custom_avatar ? 'Yes' : 'No') . "\n"; echo "Created At: " . $user->createdAt . "\n"; echo "Updated At: " . $user->updatedAt . "\n"; /* Expected output: User ID: 13546 Name: Marco Polo Email: marco@polo.com Color: #7047EB Avatar URL: https://www.gravatar.com/avatar/cc27e9f9e9a66d0fb6a988a?d=blank Has Custom Avatar: No Created At: 2023-01-18T13:56:46.000000Z Updated At: 2023-01-18T14:00:01.000000Z */ } catch (\LemonSqueezy\Exception\UnauthorizedPermissionException $e) { echo "Authentication failed: " . $e->getMessage(); } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "API error: " . $e->getMessage(); } ``` -------------------------------- ### Retrieve Single Customer Details - LemonSqueezy PHP SDK Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetches detailed information about a specific customer including ID, contact details, location, financial metrics, and account timestamps using the LemonSqueezy API. Requires API authentication and handles ResourceNotFoundException and ErrorException for robust error management. Returns formatted customer profile data with optional regional and city information. ```php authenticate('your_api_token_here'); $customerId = 596510; try { $customer = $client->customer()->getCustomer($customerId); echo "Customer Profile:\n"; echo "==================\n"; echo "ID: " . $customer->id . "\n"; echo "Store ID: " . $customer->store_id . "\n"; echo "Name: " . $customer->name . "\n"; echo "Email: " . $customer->email . "\n"; echo "Status: " . $customer->status_formatted . "\n"; if ($customer->country) { echo "\nLocation:\n"; echo " Country: " . $customer->country_formatted . "\n"; if ($customer->region) { echo " Region: " . $customer->region . "\n"; } if ($customer->city) { echo " City: " . $customer->city . "\n"; } } echo "\nFinancials:\n"; echo " Total Revenue: " . $customer->total_revenue_currency_formatted . "\n"; echo " Monthly Recurring Revenue: " . $customer->mrr_formatted . "\n"; echo "\nAccount Info:\n"; echo " Test Mode: " . ($customer->test_mode ? 'Yes' : 'No') . "\n"; echo " Created: " . $customer->created_at . "\n"; echo " Updated: " . $customer->updated_at . "\n"; } catch (\LemonSqueezy\Exception\ResourceNotFoundException $e) { echo "Customer not found with ID: " . $customerId . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Retrieve Product Variants using PHP Source: https://context7.com/seisigmasrl/lemonsqueezy.php/llms.txt Fetches all variants associated with a specific product ID. This function is useful for products that have multiple pricing options or configurations. It requires the LemonSqueezy SDK and authentication. The output lists each variant's details, including ID, name, status, and price. ```php authenticate('your_api_token_here'); $productId = 59920; try { $variants = $client->product()->getProductVariants($productId); echo "Variants for Product ID: " . $productId . "\n\n"; foreach ($variants as $variant) { echo "Variant ID: " . $variant->id . "\n"; echo "Name: " . $variant->name . "\n"; echo "Status: " . $variant->status_formatted . "\n"; echo "Price: " . $variant->price_formatted . "\n"; if ($variant->description) { echo "Description: " . $variant->description . "\n"; } echo "---\n"; } echo "\nTotal variants: " . count($variants) . "\n"; } catch (\LemonSqueezy\Exception\ResourceNotFoundException $e) { echo "Product not found with ID: " . $productId . "\n"; } catch (\LemonSqueezy\Exception\ErrorException $e) { echo "Error: " . $e->getMessage(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.