birko/najnakup
Laravel/PHP package for integrating Najnakup “overenie objednavky” (order verification). Helps verify/confirm customer orders through the Najnakup service, suitable for shops that need post-order validation and trust checks.
Install the Package
composer require birko/najnakup
Verify compatibility with your Laravel version (8.x or 9.x recommended).
Publish Configuration
php artisan vendor:publish --provider="Birko\Najnakup\NajnakupServiceProvider" --tag="config"
Update .env with Najnakup credentials:
NAJNAKUP_API_KEY=your_api_key
NAJNAKUP_API_SECRET=your_secret
NAJNAKUP_BASE_URL=https://api.najnakup.sk/v1
First Use Case: Verify Order Status
use Birko\Najnakup\Facades\Najnakup;
$orderId = 'ORD12345';
$verification = Najnakup::verify($orderId);
if ($verification->success()) {
// Order is valid; proceed with business logic
$this->processValidOrder($verification->data());
} else {
// Handle failure (e.g., log, retry, or notify user)
$this->handleVerificationError($verification->error());
}
Key Files to Inspect
config/najnakup.php: API endpoints, timeouts, and defaults.src/Facades/Najnakup.php: Main facade for quick integration.src/Exceptions/: Custom exceptions for error handling.Handle Najnakup’s real-time notifications (e.g., order updates, refunds):
use Birko\Najnakup\Facades\Najnakup;
use Illuminate\Http\Request;
public function najnakupWebhook(Request $request)
{
$payload = $request->json()->all();
$validation = Najnakup::validateWebhook($payload);
if ($validation->isValid()) {
// Process the webhook (e.g., update order in DB)
$this->syncOrderWithNajnakup($validation->data());
}
return response()->json(['status' => 'processed']);
}
Verify multiple orders efficiently (e.g., during nightly reconciliation):
$orderIds = ['ORD1', 'ORD2', 'ORD3'];
$results = Najnakup::verifyBatch($orderIds);
foreach ($results as $result) {
if ($result->success()) {
$this->updateOrderStatus($result->data());
}
}
Offload verification to a background job to avoid blocking requests:
use Birko\Najnakup\Jobs\VerifyOrderJob;
// Dispatch job
VerifyOrderJob::dispatch($orderId);
// Job implementation
public function handle()
{
$response = Najnakup::verify($this->orderId);
// Store result or trigger follow-up actions
}
Extend responses to include additional metadata or formatting:
Najnakup::extend(function ($client) {
$client->onResponse(function ($response) {
$response->setCustomField('processed_at', now());
return $response;
});
});
Bind the Najnakup client to an interface for better testability:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(
\Birko\Najnakup\Contracts\NajnakupClient::class,
\Birko\Najnakup\NajnakupClient::class
);
}
Add middleware to log or transform requests/responses:
// app/Http/Middleware/LogNajnakupRequests.php
public function handle($request, Closure $next)
{
$response = $next($request);
\Log::info('Najnakup API Response', $response->json());
return $response;
}
Trigger Laravel events after verification (e.g., OrderVerified):
// app/Listeners/HandleOrderVerification.php
public function handle($event)
{
if ($event->isVerified()) {
event(new OrderVerified($event->order));
}
}
Create CLI tools for manual verification or debugging:
php artisan najnakup:verify ORD123
// app/Console/Commands/VerifyNajnakupOrder.php
protected $signature = 'najnakup:verify {orderId}';
public function handle()
{
$result = Najnakup::verify($this->argument('orderId'));
$this->line($result->success() ? 'Verified!' : 'Failed: ' . $result->error());
}
.env and validate credentials on startup:
if (empty(config('najnakup.api_key'))) {
throw new \RuntimeException('Najnakup API key not configured.');
}
use Illuminate\Support\Facades\Queue;
Queue::later(now()->addSeconds(5), function () {
Najnakup::verify($orderId);
});
$validation = Najnakup::validateWebhook($payload, $request->header('X-Signature'));
if (!$validation->isValid()) {
abort(403, 'Invalid webhook signature');
}
Najnakup::setRetryOptions([
'max_attempts' => 3,
'delay' => 1000, // ms
]);
najnakup.php config for table names and prefix them:
'database' => [
'prefix' => 'najnakup_',
],
Najnakup::setLogLevel(\Monolog\Logger::DEBUG);
Check logs at storage/logs/laravel.log.
// tests/TestCase.php
protected function mockNajnakupClient()
{
$this->app->instance(
\Birko\Najnakup\Contracts\NajnakupClient::class,
Mockery::mock(\Birko\Najnakup\Contracts\NajnakupClient::class)
);
}
Use a middleware to log raw responses:
public function handle($request, Closure $next)
{
$response = $next($request);
\Log::debug('Najnakup Raw Response', [
'status' => $response->status(),
'body' => $response->getBody(),
]);
return $response;
}
NAJNAKUP_BASE_URL=https://staging.najnakup.sk/v1
Najnakup::extendEndpoint('custom', 'orders/{id}/custom-action');
Najnakup::setTimeout(30); // seconds
Extend the default response handler:
use Birko\Najnakup\Responses\NajnakupResponse;
class CustomNajnakupResponse extends NajnakupResponse
{
public function getFormattedData()
{
return $this->data + ['custom_field' => 'value'];
}
}
// Register in service provider
Najnakup::setResponseClass(CustomNajnakupResponse::class);
Add hooks for pre/post API calls:
Najnakup::onBeforeRequest(function ($request) {
$request->headers->set('X-Custom-Header', 'value');
How can I help you explore Laravel packages today?