PHP code example of pawanmore / stytch-php-sdk

1. Go to this page and download the library: Download pawanmore/stytch-php-sdk 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/ */

    

pawanmore / stytch-php-sdk example snippets




use Stytch\StytchClient;

// Initialize with your project credentials
$stytch = new StytchClient([
    'project_id' => 'your-project-id',
    'secret' => 'your-secret-key',
    'env' => 'test' // or 'live'
]);

// Create an organization
$response = $stytch->b2b->organizations->create([
    'organization_name' => 'My Company',
    'organization_slug' => 'my-company'
]);

// Create a member
$response = $stytch->b2b->members->create([
    'organization_id' => 'org_123',
    'email_address' => '[email protected]'
]);

// Send magic link
$response = $stytch->b2b->magicLinks->send([
    'organization_id' => 'org_123',
    'email_address' => '[email protected]'
]);

// Create a user
$response = $stytch->consumer->users->create([
    'email' => '[email protected]'
]);

// Send magic link
$response = $stytch->consumer->magicLinks->send([
    'email' => '[email protected]'
]);

// Authenticate magic link
$response = $stytch->consumer->magicLinks->authenticate([
    'token' => 'magic_link_token'
]);

try {
    $response = $stytch->consumer->users->create(['email' => 'invalid-email']);
} catch (Stytch\Exceptions\StytchException $e) {
    echo "Stytch Error: " . $e->getMessage();
} catch (Stytch\Exceptions\StytchError $e) {
    echo "API Error: " . $e->getMessage();
    echo "Error Code: " . $e->getErrorCode();
}

$stytch = new StytchClient([
    'project_id' => 'your-project-id',
    'secret' => 'your-secret-key',
    'env' => 'test',
    'timeout' => 30,
    'user_agent' => 'MyApp/1.0',
    'http_client' => new CustomHttpClient()
]);
bash
composer