composer require baks-dev/megamarket baks-dev/megamarket-orders
php artisan baks:users-profile-type:megamarket
php artisan baks:payment:megamarket
php artisan baks:delivery:megamarket
.env (check config/megamarket.php if it exists).MEGAMARKET_API_KEY and MEGAMARKET_API_SECRET are set.php artisan migrate
php artisan baks:assets:install
https://yourdomain.com/megamarket/order/new
https://yourdomain.com/megamarket/order/cancel
/megamarket/order/new with a Megamarket-compatible payload.{
"lot_id": "12345",
"buyer_id": "67890",
"items": [...],
"delivery_method": "megamarket",
"payment_method": "megamarket"
}
orders table for the new Megamarket order with associated profile_type, payment, and delivery records./megamarket/order/cancel with the lot_id:
{ "lot_id": "12345" }
Trigger: Megamarket sends a webhook to /megamarket/order/new.
Steps:
lot_id, buyer_id, items) are present.OrderService (assumed) to generate a Laravel order with Megamarket-specific metadata.$order->profile_type()->attach(MegamarketProfileType::whereName('megamarket')->first());
$order->payment()->attach(MegamarketPayment::whereName('megamarket')->first());
$order->delivery()->attach(MegamarketDelivery::whereName('megamarket')->first());
Example Controller:
public function handleOrderNew(Request $request)
{
$validated = $request->validate([
'lot_id' => 'required|string',
'buyer_id' => 'required|string',
'items' => 'required|array',
]);
$order = app(\Baks\MegamarketOrders\Services\OrderService::class)
->createFromMegamarket($validated);
return response()->json(['status' => 'order_created', 'order_id' => $order->id]);
}
Trigger: Megamarket sends a webhook to /megamarket/order/cancel.
Steps:
lot_id: Ensure the order exists in your system.$order = Order::where('megamarket_lot_id', $request->lot_id)->firstOrFail();
$order->update(['status' => 'canceled']);
Example Controller:
public function handleOrderCancel(Request $request)
{
$request->validate(['lot_id' => 'required|string']);
$order = Order::where('megamarket_lot_id', $request->lot_id)->firstOrFail();
$order->cancel();
return response()->json(['status' => 'canceled']);
}
// Customize Megamarket profile type (e.g., add fields)
$profileType = \Baks\Megamarket\Entities\UserProfileType::create([
'name' => 'megamarket_custom',
'config' => ['api_key' => 'your_key'],
]);
// Override default payment processing
event(OrderPaid::class, function ($event) {
if ($event->order->payment->name === 'megamarket') {
// Call Megamarket API to confirm payment
\Baks\Megamarket\Services\PaymentService::confirm($event->order->id);
}
});
Webhook Security:
public function handle($request, Closure $next)
{
if (!$request->hasValidSignature()) {
abort(403);
}
return $next($request);
}
Asynchronous Processing:
dispatch(new ProcessMegamarketOrder($payload))->onQueue('megamarket');
Logging:
\Log::channel('megamarket')->info('Order created', ['lot_id' => $lotId, 'data' => $payload]);
Testing:
phpunit --group=megamarket-orders
$this->mock(MegamarketApi::class)->shouldReceive('createOrder')->andReturn($mockResponse);
Configuration:
config/megamarket.php:
'api' => [
'base_url' => env('MEGAMARKET_API_URL', 'https://api.megamarket.ru'),
'timeout' => 30,
],
Missing Documentation:
Database Conflicts:
orders, payments, or deliveries tables. Backup your database before running migrate.profile_type_id, payment_id, and delivery_id columns exist in your orders table.Console Command Dependencies:
baks:users-profile-type:megamarket assume the baks-dev/megamarket package is installed. Install both packages simultaneously to avoid errors.Webhook Idempotency:
lot_id existence before processing).API Key Management:
.env; use Laravel’s config/services.php or a secrets manager.Timeouts:
Localization:
'logging' => [
'enabled' => env('MEGAMARKET_DEBUG', false),
'channel' => 'megamarket',
],
View logs with:
tail -f storage/logs/megamarket
How can I help you explore Laravel packages today?