PHP code example of lustmored / lockme-sdk

1. Go to this page and download the library: Download lustmored/lockme-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/ */

    

lustmored / lockme-sdk example snippets


use Lockme\SDK\Lockme;

$sdk = new Lockme([
    "clientId" => 'YOUR_CLIENT_ID',
    "clientSecret" => "YOUR_CLIENT_SECRET",
    "redirectUri" => 'YOUR_REDIRECT_URI',
    // Optional: Custom API domain (defaults to https://api.lock.me)
    "apiDomain" => 'https://api.lock.me'
]);

// Define the scopes you need - rooms_manage is nage']);

// Redirect the user to the authorization URL
header('Location: ' . $authUrl);
exit;

// In your callback URL handler
$code = $_GET['code'];
$state = $_GET['state'];

try {
    // Exchange the authorization code for an access token
    $accessToken = $sdk->getTokenForCode($code, $state);

    // Save the token for future use
    file_put_contents('token.json', json_encode($accessToken));
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

try {
    // Load the token from storage and set up automatic saving when refreshed
    $sdk->loadAccessToken(
        fn() => file_get_contents('token.json'),
        fn($token) => file_put_contents('token.json', json_encode($token))
    );

    // Now you can make API calls
    $rooms = $sdk->RoomList();
} catch(Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

$result = $sdk->Test();

$rooms = $sdk->RoomList();

$roomId = 123;
$room = $sdk->GetRoom($roomId);

$roomId = 123;
$data = [
    'calendarMargin' => 15, // numeric value
];
$room = $sdk->EditRoom($roomId, $data);

use DateTime;

$roomId = 123;
$date = new DateTime();
$reservations = $sdk->GetReservations($roomId, $date);

$data = [
    'date' => '2023-01-01',          // Date in YYYY-MM-DD format
    'hour' => '11:00:00',            // Time in HH:MM:SS format
    'roomid' => 123,                 // Room ID
    'extid' => 'abc123',             // External ID (your system's ID)
    'name' => 'John',                // Customer's first name
    'surname' => 'Doe',              // Customer's last name
    'email' => '[email protected]', // Customer's email
    'phone' => '+1234567890',        // Customer's phone number
    'people' => 4,                   // Number of people
    'pricer' => 1,                   // Pricer ID (pricing option)
    'comment' => 'Special requests', // Booking comment
    'price' => 100.00,               // Price
];

$reservationId = $sdk->AddReservation($data);

$roomId = 123;
$reservationId = 'abc123';
$reservation = $sdk->Reservation($roomId, $reservationId);

$roomId = 123;
$reservationId = 'abc123';
$data = [
    'name' => 'John',               // Customer's first name
    'surname' => 'Doe',             // Customer's last name
    'email' => '[email protected]', // Customer's email
    'phone' => '+1234567890',       // Customer's phone number
    'people' => 4,                  // Number of people
    'pricer' => 1,                  // Pricer ID (pricing option)
    'comment' => 'Updated requests', // Booking comment
    'price' => 100.00,              // Price
];

$result = $sdk->EditReservation($roomId, $reservationId, $data);

$roomId = 123;
$reservationId = 'abc123';
$result = $sdk->DeleteReservation($roomId, $reservationId);

$roomId = 123;
$date = new DateTime();
$settings = $sdk->GetDateSettings($roomId, $date);

$roomId = 123;
$date = new DateTime();
$settings = [                  // Specific hour settings
    [
        "hour" => "16:00:00",   // Time slot
        "pricers" => [1227],    // Available pricing options for this slot
    ],
    [
        "hour" => "18:00:00",
        "pricers" => [1227, 1228],
    ]
];

$result = $sdk->SetDateSettings($roomId, $date, $settings);