baks-dev/yandex-market-orders
Symfony/PHP модуль для работы с заказами Яндекс.Маркета: поддержка схем FBS и DBS, установка профилей пользователя, способов оплаты и доставки через консольные команды, миграции БД и установка ассетов. Тесты PHPUnit.
Installation:
composer require baks-dev/yandex-market baks-dev/yandex-market-orders
Ensure PHP 8.4+ is used.
Run Console Commands: Choose either FBS (Fast Business Service) or DBS (Delivery Business Service) and execute:
php bin/console baks:users-profile-type:yandex-market-{fbs|dbs}
php bin/console baks:payment:yandex-market-{fbs|dbs}
php bin/console baks:delivery:yandex-market-{fbs|dbs}
Configure Assets:
php bin/console baks:assets:install
Database Migrations:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
use BaksDev\YandexMarketOrders\Webhook\YandexMarketWebhookHandler;
Route::post('/yandex-market/webhook', [YandexMarketWebhookHandler::class, 'handle']);
use BaksDev\YandexMarketOrders\Service\OrderService;
$orderService = app(OrderService::class);
$order = $orderService->createOrder($yandexOrderData);
Order Lifecycle Management:
$orders = $orderService->fetchOrders($token, $sinceId);
$orderService->updateOrderStatus($orderId, 'delivered');
$orderService->cancelOrder($orderId, 'Customer requested cancellation');
Webhook Integration:
class CustomWebhookHandler extends YandexMarketWebhookHandler
{
protected function handleOrderStatusUpdate(array $data): void
{
// Custom logic for order status updates
}
}
Delivery and Payment Integration:
$deliveryService = app(\BaksDev\YandexMarketDelivery\Service\DeliveryService::class);
$deliveryService->createDelivery($orderId, $address);
OrderCreated, OrderStatusUpdated) using Laravel’s event system.
Event::listen(OrderStatusUpdated::class, function ($event) {
// Handle status update (e.g., send notification)
});
$this->logger->debug('Yandex Market API Response', ['response' => $response]);
php bin/phpunit --group=yandex-market-orders
Token Management:
.env or a secrets manager). Avoid hardcoding tokens in configuration files.Webhook Verification:
if (!$this->verifyWebhookSignature($data, $signature)) {
abort(403, 'Invalid signature');
}
Rate Limiting:
try {
$response = $client->request('GET', '/orders');
} catch (RateLimitException $e) {
sleep($e->getRetryAfter());
retry();
}
Database Schema Conflicts:
Order or Delivery entities, ensure migrations are compatible with the package’s expectations. Run doctrine:migrations:diff after changes.config/yandex-market.php to log API requests/responses:
'debug' => env('YANDEX_MARKET_DEBUG', false),
Testing facade:
$this->post('/yandex-market/webhook', $mockPayload, [
'headers' => ['X-Yandex-Signature' => $mockSignature],
]);
items array format in orders).Custom Order Fields:
Override the Order entity to add custom fields:
namespace App\Entity;
use BaksDev\YandexMarketOrders\Entity\Order as BaseOrder;
class Order extends BaseOrder
{
#[ORM\Column(nullable: true)]
private ?string $customField = null;
}
API Client Extensions: Extend the HTTP client to add custom headers or middleware:
$client = new YandexMarketClient($token, new CustomHttpClient());
Event Subscribers: Create subscribers for Yandex Market events to trigger custom logic:
class OrderStatusSubscriber implements SubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
OrderStatusUpdated::class => 'onOrderStatusUpdated',
];
}
public function onOrderStatusUpdated(OrderStatusUpdated $event): void
{
// Custom logic
}
}
Delivery/Driver Integration: Hook into the delivery service to integrate with third-party logistics providers:
$deliveryService->extend(function (Delivery $delivery) {
$delivery->setExternalTrackingId($thirdPartyTrackingId);
});
How can I help you explore Laravel packages today?