Install the Package
composer require baks-dev/ozon-package
Ensure your project uses Laravel 10+ and PHP 8.4+.
Publish Assets and Configure Run the installation command to set up configuration files and migrations:
php artisan baks:assets:install
This generates:
config/ozon.phpdatabase/migrations/config/app.php for Baks\OzonPackage\OzonPackageServiceProvider).Run Migrations Apply the database schema changes:
php artisan doctrine:migrations:migrate
Verify the ozon_orders, ozon_shipping, and related tables are created.
First Use Case: Packaging an Order
Inject the OzonOrderPackager service into a controller or command:
use Baks\OzonPackage\Services\OzonOrderPackager;
public function __construct(private OzonOrderPackager $packager) {}
public function handleOrder(Order $order) {
$packagingData = $this->packager->generatePackaging($order);
// $packagingData includes Ozon-compliant box dimensions, weight, etc.
return response()->json($packagingData);
}
Test the Integration Run the package-specific tests to validate core functionality:
php artisan test --group=ozon-package
OzonOrderPackager service to generate Ozon-compliant packaging templates.$packager = app(OzonOrderPackager::class);
$template = $packager->generatePackaging($order, [
'box_type' => 'standard', // or 'fragile', 'oversized'
'include_branding' => true,
]);
OzonPackagingConfig class or binding a custom service.OzonShippingLabelGenerator to create PLP (Prepaid Label Printing) or shipping labels.$labelGenerator = app(OzonShippingLabelGenerator::class);
$labelData = $labelGenerator->generateLabel($order, $carrier);
$labelUrl = $labelGenerator->downloadLabel($labelData);
// In a service provider or EventServiceProvider
event(new OzonWebhookReceived($payload));
order_createdorder_status_updatedshipment_sentrefund_processedOzonWebhookValidator to verify payload signatures and structure.OzonOrderSync service.$sync = app(OzonOrderSync::class);
$sync->fetchAndStoreOrders(); // Fetches from Ozon API and saves to DB
php artisan schedule:run) or as a queue job.$this->app->bind(
OzonOrderPackager::class,
fn() => new CustomOzonOrderPackager()
);
EventServiceProvider:
protected $listen = [
'ozon.order.packaged' => [
\App\Listeners\NotifyWarehouse::class,
],
];
// In a custom migration
Schema::create('ozon_orders', function (Blueprint $table) {
// Add Ozon-specific fields to your existing order table
$table->string('ozon_order_id')->unique();
$table->json('ozon_metadata');
});
OzonOrderRepository or create a custom repository that extends it.Illuminate\Support\Facades\Retry:
use Illuminate\Support\Facades\Retry;
Retry::retry(3, function () {
$response = $ozonClient->get('/orders');
}, 100); // 100ms delay between retries
\Log::channel('ozon')->info('API Request', [
'endpoint' => $endpoint,
'payload' => $payload,
'response' => $response,
]);
OzonClient interface in tests:
$this->mock(OzonClient::class)->shouldReceive('getOrders')->andReturn([...]);
Assumptions About Order Structure
weight, dimensions). If your order model differs, extend the OzonOrderMapper or create a custom mapper:
$mapper = new CustomOzonOrderMapper($order);
$ozonOrder = $mapper->map();
Webhook Signature Validation
ozon.php config includes the correct secret:
'webhook' => [
'secret' => env('OZON_WEBHOOK_SECRET'),
],
ozon.webhook to debug.Database Conflicts
orders tables. Solution:
OzonMigrations service provider.API Version Mismatches
CHANGELOG.md for API version compatibility.OzonClient to use a custom API version:
$client = new OzonClient(env('OZON_API_KEY'), 'v3');
Label Generation Dependencies
composer require dompdf/dompdf
Queue Jobs for Async Processing
GenerateOzonLabelJob::dispatch($order, $carrier);
Enable Debug Logging
Add this to config/logging.php:
'channels' => [
'ozon' => [
'driver' => 'single',
'path' => storage_path('logs/ozon.log'),
'level' => 'debug',
],
],
Then log API interactions:
\Log::ozon()->debug('Ozon API Response', ['data' => $response]);
Validate API Responses
Use the OzonResponseValidator to check for errors:
$validator = new OzonResponseValidator();
if (!$validator->isValid($response)) {
\Log::error('Invalid Ozon API response', ['errors' => $validator->getErrors()]);
}
Test Webhooks Locally
Use Laravel’s queue:work to process webhooks in development:
php artisan queue:work
Simulate webhooks with:
php artisan ozons:webhook:test order_created
Check for Deprecated Methods The package may use deprecated Ozon API endpoints. Solution:
How can I help you explore Laravel packages today?