Install and Configure
composer require baks-dev/four-tochki-orders
php artisan vendor:publish --provider="BaksDev\FourTochkiOrders\FourTochkiOrdersBundle" --tag="config"
php artisan baks:assets:install # Copies assets to public/4tochki
php artisan doctrine:migrations:migrate # Runs bundle migrations
First Order Fetch
Use the OrderService to pull orders from 4tochki:
use BaksDev\FourTochkiOrders\Service\OrderService;
public function fetchOrders(OrderService $orderService) {
$orders = $orderService->getOrders(['status' => 'new', 'limit' => 10]);
foreach ($orders as $order) {
// Process order (e.g., create in your Laravel DB)
\App\Models\Order::create($order->toArray());
}
}
OrderService: Core API interaction.Order: Doctrine entity (map to Eloquent if needed).FourTochkiOrdersBundle: Bundle configuration.Webhook Setup (Optional)
If 4tochki supports webhooks, configure the bundle’s listener in config/four_tochki_orders.php:
'webhooks' => [
'enabled' => true,
'secret' => env('FOURTOCHKI_WEBHOOK_SECRET'),
'routes' => [
'order.created' => 'app\Http\Controllers\FourTochkiWebhookController@handleOrderCreated',
],
],
routes/web.php (Symfony’s routing.yml may need conversion).Environment Variables
Add to .env:
FOURTOCHKI_API_KEY=your_api_key
FOURTOCHKI_API_SECRET=your_secret
FOURTOCHKI_SHOP_ID=your_shop_id
OrderService in a scheduled job (e.g., Laravel’s schedule:run).// app/Console/Commands/FetchFourTochkiOrders.php
use BaksDev\FourTochkiOrders\Service\OrderService;
use Illuminate\Console\Command;
class FetchFourTochkiOrders extends Command {
public function handle(OrderService $orderService) {
$orders = $orderService->getOrders(['status' => 'pending']);
foreach ($orders as $order) {
$this->processOrder($order);
}
}
}
// app/Console/Kernel.php
protected function schedule(Schedule $schedule) {
$schedule->command('fetch:fourtochki-orders')->hourly();
}
// app/Http/Middleware/ValidateFourTochkiWebhook.php
public function handle($request, Closure $next) {
$payload = $request->getContent();
$signature = $request->header('X-FourTochki-Signature');
if (!$this->validateSignature($payload, $signature)) {
abort(403);
}
return $next($request);
}
Route::post('/4tochki/webhook', [FourTochkiWebhookController::class, 'handle'])
->middleware('validate.fourtochki-webhook');
InventoryService to update stock levels.use BaksDev\FourTochkiOrders\Service\InventoryService;
public function syncInventory(InventoryService $inventoryService) {
$products = $inventoryService->getProducts();
foreach ($products as $product) {
Product::where('sku', $product->getSku())
->update(['stock' => $product->getQuantity()]);
}
}
$container = app()->make('BaksDev\FourTochkiOrders\FourTochkiOrdersBundle')->getContainer();
$orderService = $container->get('baks_fourtochki.order_service');
// Symfony event (bundle)
$dispatcher->dispatch(new OrderCreatedEvent($order));
// Laravel equivalent
event(new \App\Events\OrderCreated($order));
laravel-doctrine/bridge to share entities.class FourTochkiOrder extends Model {
protected $casts = [
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
public static function fromDoctrineEntity(\BaksDev\FourTochkiOrders\Entity\Order $entity) {
return self::create([
'id' => $entity->getId(),
'total' => $entity->getTotal(),
// ...
]);
}
}
// app/Console/Commands/InstallFourTochkiAssets.php
use Illuminate\Console\Command;
class InstallFourTochkiAssets extends Command {
public function handle() {
$this->copyAssets();
$this->publishConfig();
}
protected function copyAssets() {
$this->files->copyDirectory(
__DIR__.'/../../vendor/baks-dev/four-tochki-orders/resources/assets',
public_path('4tochki')
);
}
}
Doctrine vs. Eloquent Conflicts
laravel-doctrine/orm.class FourTochkiOrder extends \Doctrine\ORM\Mapping\Entity {
// Doctrine entity
}
class LaravelFourTochkiOrder extends Model {
public static function fromDoctrine(FourTochkiOrder $entity) {
return self::create([
'id' => $entity->getId(),
// ...
]);
}
}
Symfony-Specific Assumptions
Container, EventDispatcher, and Console components.class LaravelOrderService {
public function __construct(private OrderService $symfonyService) {}
public function getOrders(array $filters) {
return $this->symfonyService->getOrders($filters);
}
}
Webhook Signature Validation
public function validateWebhook($payload, $signature) {
$expected = hash_hmac('sha256', $payload, env('FOURTOCHKI_WEBHOOK_SECRET'));
return hash_equals($expected, $signature);
}
Migration Conflicts
php artisan doctrine:migrations:migrate --path=vendor/baks-dev/four-tochki-orders/migrations
DB::transaction(function () {
// Run Laravel migrations
Schema::create('laravel_orders', function (Blueprint $table) { ... });
// Run Doctrine migrations (if needed)
});
PHP 8.4+ Requirements
composer require php:^8.4
Enable Bundle Debugging
Add to config/four_tochki_orders.php:
'debug' => env('APP_DEBUG', false),
Log Symfony Events Subscribe to Symfony events in Laravel:
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
public
How can I help you explore Laravel packages today?