### Install Tebex PHP SDK via Composer Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Use Composer to install the Tebex SDK. Ensure you have Composer installed and configured. ```bash composer require tebex/tebex-sdk-php ``` -------------------------------- ### Headless API - Interact with Tebex Project Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Initialize the Headless API with your public token and interact with categories, packages, and create baskets. Handles user authentication if required. ```php $project = Headless::setProject("your-public-token"); // Interact with the project through $project $categories = $project->listCategories(); $packages = $project->listPackages(); $project->getCategory(12345); $project->getPackage(67890); // Create baskets through the project, providing completion and cancellation urls $basket = $project->createBasket("https://tebex.io/completed", "https://tebex.io/cancelled"); // If the project requires auth, direct the user to authorize before adding packages if ($project->requiresUserAuth()) { $authUrl = $project->getUserAuthUrl($basket, "https://tebex.io/auth-return"); echo "- User auth required at: " . $authUrl . ".\n"; } // Once user is successfully authed we can add packages via $basket $package = $packages[0]; $basket = $basket->addPackage($package); $basket = $basket->addGiftedPackage($package, "Tebex"); $basket = $basket->addGiftCardPackage($package, "tebex-integrations@overwolf.com"); // You can also add variable data as needed per each package $basket->addPackage($package, [ "server_id" => "127244" ]); // Each function returns the remote basket after completion, but you can always request the current basket from the API $basket = $basket->refreshBasket(); // Query the $basket object for any info echo "Price: $" . $basket->getBasePrice() . "\n"; // Go to checkout $checkoutLink = $basket->getLinks()->getCheckout(); echo "Checkout at: " . $checkoutLink; ``` -------------------------------- ### Checkout API - Set API Keys Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Authorize the Checkout API using your project ID and private key. This step is required before making any Checkout API calls. ```php // Authorize your store using your API keys Checkout::setApiKeys("projectId", "privateKey"); ``` -------------------------------- ### Create a Checkout Request Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Use Checkout::checkoutRequest to send basket information and products in a single request. The list of packages should be an array of CheckoutItem, which can be provided by the PackageBuilder with buildCheckoutItem(). ```php $builder = Checkout\BasketBuilder::new() ->email("support@tebex.io")->firstname("Tebex")->lastname("Support") ->ip($_SERVER["REMOTE_ADDR"]) ->returnUrl("https://tebex.io/")->completeUrl("https://tebex.io/"); $package1 = Checkout\PackageBuilder::new()->name("100 Gold")->qty(1)->price(1.27)->oneTime(); $basket = Checkout::checkoutRequest($builder, [$package1->buildCheckoutItem()]); echo "Checkout at: " . $basket->getLinks()->getCheckout(); ``` -------------------------------- ### Include Composer Autoloader Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Include Composer's autoloader to make the Tebex library available in your PHP project. ```php require_once 'vendor/autoload.php'; ``` -------------------------------- ### Checkout API - Create Packages with PackageBuilder Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Define packages for the Checkout API using PackageBuilder. Supports one-time purchases and recurring subscriptions with specified quantities and prices. ```php $package1 = Checkout\PackageBuilder::new()->name("100 Gold")->qty(1)->price(1.27) ->oneTime(); $package2 = Checkout\PackageBuilder::new()->name("1 Month Sub")->qty(1)->price(2.44) ->subscription()->monthly()->expiryLength(1); ``` -------------------------------- ### Checkout API - Create Basket with BasketBuilder Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Use the BasketBuilder to construct a basket for the Checkout API. Set customer details, return URLs, and completion URLs. ```php // Use the BasketBuilder to create your basket for Checkout $builder = Checkout\BasketBuilder::new() ->email("tebex-integrations@overwolf.com") ->firstname("Tebex") ->lastname("Integrations") ->ip("127.0.0.1") // provide client IP if running on your backend server ->returnUrl("https://tebex.io/") ->completeUrl("https://tebex.io/"); ``` -------------------------------- ### Webhook - Set Secret Key and Parse Incoming Webhook Source: https://github.com/tebexio/tebex-sdk-php/blob/master/README.md Configure the webhook secret key for validation and parse incoming webhook data from php://input. This is crucial for verifying the authenticity of webhook events. ```php // You must set your secret key first so that webhooks can be validated. Webhooks::setSecretKey("2248c2227ac29e5cbdbab44ed6a0f961"); // Is read from php://input unless an argument is provided $webhook = Webhook::parse(); // You can check for specific webhook types if ($webhook->isType("\Tebex\Webhook\VALIDATION_WEBHOOK")) { echo json_encode(["id" => $webhook->getId()]); // Respond to validation endpoint } // You can quickly check the type of webhook with helper functions as well else if ($webhook->isTypeOfPayment() || $webhook->isTypeOfDispute()) { // The "subject" contains data about the webhook action $pmtSubject = $webhook->getSubject(); // type is \TebexCheckout\Model\PaymentSubject // etc.... } else if ($webhook->isTypeOfRecurringPayment()) { $recurringPmtSubject = $webhook->getSubject(); // \TebexCheckout\Model\RecurringPaymentSubject // etc... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.