PHP code example of tebex / tebex-sdk-php

1. Go to this page and download the library: Download tebex/tebex-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tebex / tebex-sdk-php example snippets




$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 [email protected]");

// 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;

// 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...
}

// Authorize your store using your API keys
Checkout::setApiKeys("projectId", "privateKey");

// Use the BasketBuilder to create your basket for Checkout
$builder = Checkout\BasketBuilder::new()
    ->email("[email protected]")
    ->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/");

$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);

$builder = Checkout\BasketBuilder::new()
    ->email("[email protected]")->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();
bash
composer