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:
twotalesanimation
2026-01-02 14:35:01 +02:00
parent 12aadfd917
commit 783cc88c6d
7 changed files with 295 additions and 41 deletions
+17 -12
View File
@@ -10,6 +10,9 @@ use App\Models\PrintStock;
use App\Services\ShippingService;
use App\Services\InvoiceService;
use App\Services\MailjetService;
use App\Events\OrderCreated;
use App\Events\DepositPaid;
use App\Events\BalancePaid;
use Illuminate\Http\Request;
class OrderController extends Controller
@@ -562,7 +565,7 @@ class OrderController extends Controller
if ($order->payment_status !== 'paid') {
$order->update([
'payment_status' => 'paid',
'status' => 'processing',
'status' => 'prep',
'yoco_checkout_response' => json_encode($payload),
]);
@@ -609,6 +612,10 @@ class OrderController extends Controller
'error' => $e->getMessage(),
]);
}
// Emit OrderCreated and DepositPaid events (standard orders are fully paid upfront)
OrderCreated::dispatch($order, 'standard');
DepositPaid::dispatch($order, $order->total); // Full payment is treated as deposit confirmation
\Log::info('Yoco Webhook: Order updated for successful payment', [
'order_uuid' => $orderUuid,
@@ -645,10 +652,14 @@ class OrderController extends Controller
if ($orderType === 'custom_deposit' && $order->deposit_status !== 'paid') {
$order->update([
'deposit_status' => 'paid',
'status' => 'submitted',
'status' => 'design',
'yoco_checkout_response' => json_encode($payload),
]);
// Emit events for custom order deposit
OrderCreated::dispatch($order, 'custom');
DepositPaid::dispatch($order, $order->deposit_amount);
\Log::info('Yoco Webhook: Order updated for successful deposit payment', [
'order_uuid' => $orderUuid,
'order_id' => $order->id,
@@ -658,10 +669,13 @@ class OrderController extends Controller
} elseif ($orderType === 'custom_balance' && $order->balance_status !== 'paid') {
$order->update([
'balance_status' => 'paid',
'status' => 'in production',
'status' => 'printing',
'yoco_checkout_response' => json_encode($payload),
]);
// Emit BalancePaid event
BalancePaid::dispatch($order, $order->balance_amount);
\Log::info('Yoco Webhook: Order updated for successful balance payment', [
'order_uuid' => $orderUuid,
'order_id' => $order->id,
@@ -691,17 +705,11 @@ class OrderController extends Controller
return response()->json(['status' => 'success']);
}
/**
* Show the track order search form
*/
public function trackForm()
{
return view('track-order');
}
/**
* Search for an order by order number and email
*/
public function trackSearch(Request $request)
{
$key = 'track-order:' . $request->ip();
@@ -732,9 +740,6 @@ class OrderController extends Controller
return view('track-order-result', ['order' => $order]);
}
/**
* Generate basic HTML template for invoice email
*/
private function getBasicInvoiceHtml(Order $order): string
{
return <<<HTML