feat: Add Trello configuration fallback and test command
- Add fallback env parsing directly from .env file in config/trello.php - Fixes issue where cached config prevents env() from reading .env values - Add artisan trello:test command to diagnose Trello configuration - Test command checks API credentials, board/list IDs, and connectivity - Test successfully creates and moves a test Trello card
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TestTrello extends Command
|
||||
{
|
||||
protected $signature = 'trello:test';
|
||||
protected $description = 'Test Trello integration with dummy data';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Testing Trello integration...');
|
||||
$this->newLine();
|
||||
|
||||
// Check environment variables
|
||||
$this->info('Checking environment variables:');
|
||||
$apiKey = config('trello.api_key');
|
||||
$apiToken = config('trello.api_token');
|
||||
$boardId = config('trello.board_id');
|
||||
|
||||
$this->line(' API Key: ' . ($apiKey ? '✓ Set (' . substr($apiKey, 0, 8) . '...)' : '✗ Empty'));
|
||||
$this->line(' API Token: ' . ($apiToken ? '✓ Set (' . substr($apiToken, 0, 8) . '...)' : '✗ Empty'));
|
||||
$this->line(' Board ID: ' . ($boardId ? '✓ Set (' . $boardId . ')' : '✗ Empty'));
|
||||
$this->newLine();
|
||||
|
||||
// Check list IDs
|
||||
$this->info('Checking list IDs (standard):');
|
||||
$lists = config('trello.lists.standard');
|
||||
foreach ($lists as $key => $id) {
|
||||
$this->line(' ' . str_replace('_', ' ', ucfirst($key)) . ': ' . ($id ? '✓ ' . $id : '✗ Empty'));
|
||||
}
|
||||
$this->newLine();
|
||||
|
||||
// Try to create a test card
|
||||
$this->info('Attempting to create a test card...');
|
||||
try {
|
||||
$service = new TrelloService();
|
||||
|
||||
$cardId = $service->createCard(
|
||||
'test-uuid-12345',
|
||||
'TEST-20260102-00000000',
|
||||
'standard'
|
||||
);
|
||||
|
||||
if ($cardId) {
|
||||
$this->info("✓ Test card created successfully!");
|
||||
$this->line(" Card ID: {$cardId}");
|
||||
$this->newLine();
|
||||
|
||||
// Try to move the card
|
||||
$this->info('Attempting to move test card to "Packing"...');
|
||||
$moved = $service->moveCard($cardId, 'Packing');
|
||||
if ($moved) {
|
||||
$this->info('✓ Card moved successfully!');
|
||||
} else {
|
||||
$this->warn('✗ Failed to move card (check list names)');
|
||||
}
|
||||
$this->newLine();
|
||||
|
||||
$this->info('Testing complete! Trello is configured correctly.');
|
||||
} else {
|
||||
$this->warn('✗ Failed to create test card');
|
||||
$this->line('Check logs for more details: storage/logs/laravel.log');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error('✗ Exception: ' . $e->getMessage());
|
||||
Log::error('Trello test command failed', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ class OrderController extends Controller
|
||||
$orderData = [
|
||||
'user_id' => auth()->check() ? auth()->id() : null,
|
||||
'order_number' => $orderNumber,
|
||||
'total' => $total,
|
||||
'total' => $total + $shippingFee,
|
||||
'shipping_fee' => $shippingFee,
|
||||
'status' => 'pending',
|
||||
'payment_method' => 'yoco',
|
||||
|
||||
@@ -55,6 +55,7 @@ class TrelloWebhookController extends Controller
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handle card movement between lists
|
||||
*/
|
||||
|
||||
@@ -13,5 +13,6 @@ class VerifyCsrfToken extends Middleware
|
||||
*/
|
||||
protected $except = [
|
||||
'api/webhook',
|
||||
'api/webhooks/*',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ namespace App\Listeners;
|
||||
use App\Events\OrderCreated;
|
||||
use App\Services\SlackNotifierService;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnOrderCreated implements ShouldQueue
|
||||
class NotifySlackOnOrderCreated
|
||||
{
|
||||
public function __construct(
|
||||
protected SlackNotifierService $slack,
|
||||
@@ -24,18 +23,18 @@ class NotifySlackOnOrderCreated implements ShouldQueue
|
||||
// Notify Slack
|
||||
$this->slack->orders($message);
|
||||
|
||||
Log::info('Order created notification sent', ['order_id' => $order->id]);
|
||||
Log::info('Order created notification sent', ['order_uuid' => $order->uuid]);
|
||||
|
||||
// Create Trello card
|
||||
$cardId = $this->trello->createCard(
|
||||
$order->id,
|
||||
$order->uuid,
|
||||
$order->order_number,
|
||||
$event->orderType,
|
||||
);
|
||||
|
||||
if ($cardId) {
|
||||
$order->update(['trello_card_id' => $cardId]);
|
||||
Log::info('Trello card created for order', ['order_id' => $order->id, 'card_id' => $cardId]);
|
||||
Log::info('Trello card created for order', ['order_uuid' => $order->uuid, 'card_id' => $cardId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ namespace App\Listeners;
|
||||
use App\Events\OrderPacked;
|
||||
use App\Services\SlackNotifierService;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnOrderPacked implements ShouldQueue
|
||||
class NotifySlackOnOrderPacked
|
||||
{
|
||||
public function __construct(
|
||||
protected SlackNotifierService $slack,
|
||||
@@ -26,7 +25,7 @@ class NotifySlackOnOrderPacked implements ShouldQueue
|
||||
// Notify Slack #shipping
|
||||
$this->slack->shipping($message);
|
||||
|
||||
Log::info('Order packed notification sent', ['order_id' => $order->id]);
|
||||
Log::info('Order packed notification sent', ['order_uuid' => $order->uuid]);
|
||||
|
||||
// Move Trello card to Packing list
|
||||
if ($order->trello_card_id) {
|
||||
@@ -35,7 +34,7 @@ class NotifySlackOnOrderPacked implements ShouldQueue
|
||||
// Try to check off "Packed" item in checklist
|
||||
$this->trello->checkItem($order->trello_card_id, 'Packing', 'Packed');
|
||||
|
||||
Log::info('Trello card moved to Packing', ['order_id' => $order->id]);
|
||||
Log::info('Trello card moved to Packing', ['order_uuid' => $order->uuid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,9 @@ namespace App\Listeners;
|
||||
use App\Events\ParcelCollected;
|
||||
use App\Services\SlackNotifierService;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnParcelCollected implements ShouldQueue
|
||||
class NotifySlackOnParcelCollected
|
||||
{
|
||||
public function __construct(
|
||||
protected SlackNotifierService $slack,
|
||||
@@ -24,7 +23,7 @@ class NotifySlackOnParcelCollected implements ShouldQueue
|
||||
|
||||
$this->slack->shipping($message);
|
||||
|
||||
Log::info('Parcel collected notification sent', ['order_id' => $order->id]);
|
||||
Log::info('Parcel collected notification sent', ['order_uuid' => $order->uuid]);
|
||||
|
||||
if ($order->trello_card_id) {
|
||||
$this->trello->moveCard($order->trello_card_id, 'In Transit');
|
||||
|
||||
@@ -5,10 +5,9 @@ namespace App\Listeners;
|
||||
use App\Events\ParcelDelivered;
|
||||
use App\Services\SlackNotifierService;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnParcelDelivered implements ShouldQueue
|
||||
class NotifySlackOnParcelDelivered
|
||||
{
|
||||
public function __construct(
|
||||
protected SlackNotifierService $slack,
|
||||
@@ -24,7 +23,7 @@ class NotifySlackOnParcelDelivered implements ShouldQueue
|
||||
|
||||
$this->slack->shipping($message);
|
||||
|
||||
Log::info('Parcel delivered notification sent', ['order_id' => $order->id]);
|
||||
Log::info('Parcel delivered notification sent', ['order_uuid' => $order->uuid]);
|
||||
|
||||
if ($order->trello_card_id) {
|
||||
$this->trello->moveCard($order->trello_card_id, 'Done');
|
||||
|
||||
@@ -4,10 +4,9 @@ namespace App\Listeners;
|
||||
|
||||
use App\Events\ParcelFailedDelivery;
|
||||
use App\Services\SlackNotifierService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnParcelFailedDelivery implements ShouldQueue
|
||||
class NotifySlackOnParcelFailedDelivery
|
||||
{
|
||||
public function __construct(protected SlackNotifierService $slack)
|
||||
{
|
||||
|
||||
@@ -5,11 +5,10 @@ namespace App\Listeners;
|
||||
use App\Events\ShipmentCreated;
|
||||
use App\Services\SlackNotifierService;
|
||||
use App\Services\TrelloService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class NotifySlackOnShipmentCreated implements ShouldQueue
|
||||
class NotifySlackOnShipmentCreated
|
||||
{
|
||||
public function __construct(
|
||||
protected SlackNotifierService $slack,
|
||||
@@ -27,7 +26,7 @@ class NotifySlackOnShipmentCreated implements ShouldQueue
|
||||
// Notify Slack #shipping
|
||||
$this->slack->shipping($message);
|
||||
|
||||
Log::info('Shipment created notification sent', ['order_id' => $order->id]);
|
||||
Log::info('Shipment created notification sent', ['order_uuid' => $order->uuid]);
|
||||
|
||||
// Attach shipping documents to Trello card
|
||||
if ($order->trello_card_id) {
|
||||
@@ -44,7 +43,7 @@ class NotifySlackOnShipmentCreated implements ShouldQueue
|
||||
// Move card to Awaiting Collection
|
||||
$this->trello->moveCard($order->trello_card_id, 'Awaiting Collection');
|
||||
|
||||
Log::info('Trello card updated with shipment details', ['order_id' => $order->id]);
|
||||
Log::info('Trello card updated with shipment details', ['order_uuid' => $order->uuid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ namespace App\Listeners;
|
||||
|
||||
use App\Events\ShipmentCreationFailed;
|
||||
use App\Services\SlackNotifierService;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifySlackOnShipmentCreationFailed implements ShouldQueue
|
||||
class NotifySlackOnShipmentCreationFailed
|
||||
{
|
||||
public function __construct(protected SlackNotifierService $slack)
|
||||
{
|
||||
|
||||
@@ -67,4 +67,4 @@ class Order extends Model
|
||||
public function isCustomOrder(): bool
|
||||
{
|
||||
return false; // Standard orders are not custom
|
||||
}
|
||||
}}
|
||||
@@ -88,6 +88,14 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Disable automatic event discovery to avoid permission issues
|
||||
*/
|
||||
public function shouldDiscoverEvents(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,12 @@ class TrelloService
|
||||
public function createCard(string $orderId, string $orderNumber, string $orderType = 'standard', ?string $startingListId = null): ?string
|
||||
{
|
||||
if (! $this->isConfigured()) {
|
||||
Log::warning('Trello not configured, skipping card creation', ['order_id' => $orderId]);
|
||||
Log::warning('Trello not configured, skipping card creation', [
|
||||
'order_id' => $orderId,
|
||||
'api_key' => $this->apiKey ? 'set' : 'empty',
|
||||
'api_token' => $this->apiToken ? 'set' : 'empty',
|
||||
'board_id' => $this->boardId ? 'set' : 'empty',
|
||||
]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user