1. Go to this page and download the library: Download letbar/loketqris-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/ */
// routes/api.php
use Letbar\LoketQrisSdk\Http\Controllers\TokenController;
use Letbar\LoketQrisSdk\Http\Controllers\NotificationController;
use Letbar\LoketQrisSdk\Http\Middleware\VerifyLoketQrisSignature;
use Letbar\LoketQrisSdk\Http\Middleware\VerifyBearerToken;
Route::post('/custom/token', [TokenController::class, 'store'])
->middleware(VerifyLoketQrisSignature::class);
Route::post('/custom/notify', [NotificationController::class, 'store'])
->middleware(VerifyBearerToken::class);
// app/Services/TenantCredentialResolver.php
namespace App\Services;
use App\Models\Credential;
use Letbar\LoketQrisSdk\Contracts\CredentialResolver;
class TenantCredentialResolver implements CredentialResolver
{
public function resolveClientSecret(string $kodeLoket, string $apiKey): ?string
{
$credential = Credential::query()
->where('kode_loket', $kodeLoket)
->where('api_key', $apiKey)
->first();
return $credential?->client_secret;
}
}
// app/Providers/AppServiceProvider.php
use App\Services\TenantCredentialResolver;
use Letbar\LoketQrisSdk\Contracts\CredentialResolver;
public function register(): void
{
$this->app->bind(CredentialResolver::class, TenantCredentialResolver::class);
}
use Letbar\LoketQrisSdk\Exceptions\ApiRequestException;
use Letbar\LoketQrisSdk\Exceptions\ConfigurationException;
use Letbar\LoketQrisSdk\Exceptions\InvalidCredentialException;
use Letbar\LoketQrisSdk\Exceptions\InvalidSignatureException;
try {
$response = LoketQris::generate($request);
} catch (ConfigurationException $e) {
// Missing base_url or credentials
} catch (InvalidCredentialException $e) {
// Empty or invalid credential fields
} catch (ApiRequestException $e) {
// API returned an error
$httpStatus = $e->getHttpStatusCode();
$responseCode = $e->getResponseCode();
$responseBody = $e->getResponseBody();
}
use Carbon\Carbon;
use Letbar\LoketQrisSdk\SignatureGenerator;
use Letbar\LoketQrisSdk\DTOs\CredentialData;
// Generate signature
$result = SignatureGenerator::generate(
kodeLoket: 'LK000001',
clientSecret: 'your-secret',
timestamp: Carbon::now() // optional
);
$timestamp = $result['timestamp']; // ISO 8601 format
$signature = $result['signature']; // Base64 encoded
// Or from credential
$credential = CredentialData::make('LK000001', 'api-key', 'secret');
$result = SignatureGenerator::fromCredential($credential);
// Verify signature
$isValid = SignatureGenerator::verify(
kodeLoket: 'LK000001',
clientSecret: 'your-secret',
timestamp: '2026-01-28T12:00:00+07:00',
signature: 'base64-signature'
);