feat: Update Order/CustomOrder models and controllers with event integration
- Add integration fields to Order model: packing_*, courier_*, trello_card_id, qr_token
- Add integration fields to CustomOrder model: packing_*, proof_approved_*, courier_*, trello_card_id, qr_token
- Update Order model fillable array and add relationships (packedBy)
- Update CustomOrder model fillable array, casts, and add relationships (packedBy)
- Add isCustomOrder() method to both models for type checking
- Update OrderController to emit OrderCreated and DepositPaid events on successful payment
- For standard orders: full payment -> prep status, emit events
- For custom orders: deposit -> design status, balance -> printing status, emit respective events
- Add approveProof() method to CustomOrderController (POST /custom-orders/{id}/approve-proof)
- Add requestChanges() method to CustomOrderController (POST /custom-orders/{id}/request-changes)
- Add markBalancePaid() method to CustomOrderController (POST /custom-orders/{id}/pay-balance)
- All new methods emit appropriate events (ProofApproved, ProofRevisionRequested, BalancePaid)
- Add database migration for proof_approved and proof_approved_at fields on custom_orders
- Add routes for new custom order endpoints with UUID binding
- Import all required event classes in both controllers
This commit is contained in:
@@ -14,36 +14,47 @@ class TrelloWebhookController extends Controller
|
||||
* POST /api/webhooks/trello
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
// Verify webhook signature
|
||||
$signature = $request->header('X-Trello-Webhook');
|
||||
if (! $this->verifyWebhookSignature($request, $signature)) {
|
||||
Log::warning('Invalid Trello webhook signature');
|
||||
|
||||
return response()->json(['error' => 'Invalid signature'], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = $request->json()->all();
|
||||
|
||||
// Log webhook for debugging
|
||||
Log::info('Trello webhook received', ['action' => $payload['action']['type'] ?? 'unknown']);
|
||||
|
||||
// Handle based on action type
|
||||
match ($payload['action']['type'] ?? null) {
|
||||
'updateCard' => $this->handleCardUpdate($payload),
|
||||
'updateCheckItem' => $this->handleChecklistUpdate($payload),
|
||||
default => Log::info('Unhandled Trello action', ['type' => $payload['action']['type'] ?? 'unknown']),
|
||||
};
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error processing Trello webhook', ['error' => $e->getMessage()]);
|
||||
|
||||
return response()->json(['error' => 'Processing failed'], 500);
|
||||
}
|
||||
{
|
||||
// 1️⃣ Trello webhook validation ping (no payload, no signature)
|
||||
if ($request->getContent() === '' || ! $request->hasHeader('X-Trello-Webhook')) {
|
||||
Log::info('Trello webhook validation ping received');
|
||||
return response()->json(['ok' => true], 200);
|
||||
}
|
||||
|
||||
// 2️⃣ Verify webhook signature (real events only)
|
||||
$signature = $request->header('X-Trello-Webhook');
|
||||
if (! $this->verifyWebhookSignature($request, $signature)) {
|
||||
Log::warning('Invalid Trello webhook signature');
|
||||
return response()->json(['error' => 'Invalid signature'], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = $request->json()->all();
|
||||
|
||||
Log::info('Trello webhook received', [
|
||||
'action' => $payload['action']['type'] ?? 'unknown',
|
||||
]);
|
||||
|
||||
match ($payload['action']['type'] ?? null) {
|
||||
'updateCard' => $this->handleCardUpdate($payload),
|
||||
'updateCheckItem' => $this->handleChecklistUpdate($payload),
|
||||
default => Log::info('Unhandled Trello action', [
|
||||
'type' => $payload['action']['type'] ?? 'unknown',
|
||||
]),
|
||||
};
|
||||
|
||||
return response()->json(['success' => true], 200);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Error processing Trello webhook', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// ⚠️ Still return 200 so Trello does not disable the webhook
|
||||
return response()->json(['error' => 'Processing failed'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle card movement between lists
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user